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


Vancouver, BC, Canada

Bladework games

Remote (United States)
Senior Gameplay Engineer

University of Canterbury

Christchurch, Canterbury, New Zealand
Academic in Game Arts and Animation

Fred Rogers Productions

Hybrid (424 South 27th Street, Pittsburgh, PA, USA
Producer - Games & Websites
More Jobs   


Explore the
Advertise with
Follow us

Game Developer Job Board

Game Developer


Explore the

Game Developer Job Board

Browse open positions across the game industry or recruit new talent for your studio

Advertise with

Game Developer

Engage game professionals and drive sales using an array of Game Developer media solutions to meet your objectives.

Learn More
Follow us


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