2 min read

UE4Cookery CPP011: Simple Pause/UnPause implementation

Topic: Simple Pause implementation Source for UE4.27:

In many games developers implement Pause/UnPause logic to allow players to have a short break or just to block everything in game while player is walking through UI things. Here we'll be using very simple and short approach.

First of all, engine has two different types of time:

  • FSlateApplication time - is the time from Operation System and it measures real time (our World time). It is used mainly for real time calculations, stats and UI animation.
  • UWorld time - is the time from game World and it is simulated by engine itself (game World time). All actors and objects of scene are living according to that one.

So, when we talk about Pause/UnPause logic, pausing is applied to UWorld time. With all of that in mind, first step of implementing Pause/UnPause mechanism will be to create custom UPawn class, add appropriate Input Action Mapping to it and bind this action. It will something like this:



#pragma once

#include "GameFramework/DefaultPawn.h"
#include "MyDefaultPawn.generated.h"

class CPP011_A_API AMyDefaultPawn : public ADefaultPawn


    virtual void SetupPlayerInputComponent(UInputComponent* InInputComponent) override;

    void OnPause();



#include "MyDefaultPawn.h"
#include "GameFramework/PlayerInput.h"
#include "Kismet/GameplayStatics.h"

const FName InputAction_Pause = FName("Pause");

void AMyDefaultPawn::SetupPlayerInputComponent(UInputComponent* InInputComponent)

    UPlayerInput::AddEngineDefinedActionMapping(FInputActionKeyMapping(InputAction_Pause, EKeys::P));

    InInputComponent->BindAction(InputAction_Pause, EInputEvent::IE_Pressed, this, &AMyDefaultPawn::OnPause);

void AMyDefaultPawn::OnPause()
    bool isNowPaused = !UGameplayStatics::IsGamePaused(this);

    UGameplayStatics::SetGamePaused(this, isNowPaused);

    UE_LOG(LogTemp, Warning, TEXT("%s"), *FString(isNowPaused ? "GAME IS PAUSED!" : "GAME IS OK!"));


Everything looks fine. However, when we will try this no any Input will be processed by our handler after we paused UWorld time. This is happening because pawns are actors and they are living according to UWorld time. When it is paused, same thing occurs with all actors, their parts and components. Thus, our pawn will not consume any Input at this state.

Well, engine has straightforward solution for this case. We only need to replace this line of code


    InInputComponent->BindAction(InputAction_Pause, EInputEvent::IE_Pressed, this, &AMyDefaultPawn::OnPause);


by this one:


    InInputComponent->BindAction(InputAction_Pause, EInputEvent::IE_Pressed, this, &AMyDefaultPawn::OnPause).bExecuteWhenPaused = true;


and now everything works as we want.

Latest Jobs


Playa Vista, California
Audio Engineer

Digital Extremes

London, Ontario, Canada
Communications Director

High Moon Studios

Carlsbad, California
Senior Producer

Build a Rocket Boy Games

Edinburgh, Scotland
Lead UI Programmer
More Jobs   


Register for a
Subscribe to
Follow us

Game Developer Account

Game Developer Newsletter


Register for a

Game Developer Account

Gain full access to resources (events, white paper, webinars, reports, etc)
Single sign-on to all Informa products

Subscribe to

Game Developer Newsletter

Get daily Game Developer top stories every morning straight into your inbox

Follow us


Follow us @gamedevdotcom to stay up-to-date with the latest news & insider information about events & more