RealDocs

AGameModeBase::SetPause

function Engine Since 4.14
#include "GameFramework/GameModeBase.h"
Access: public Specifiers: virtualENGINE_API

Description

Requests the game be paused on behalf of a PlayerController. Registers a CanUnpause delegate that must return true before the pause is lifted. Returns true if the pause was successfully applied.

Caveats & Gotchas

  • Multiple callers can each add their own CanUnpause delegate. The game only unpauses when every delegate in the list returns true — one requestor cannot unilaterally cancel another's pause.
  • Pause only takes effect if bPauseable is true on the GameMode and AllowPausing() returns true for the requesting controller. Dedicated servers typically override this to prevent pausing.

Signature

virtual bool SetPause(APlayerController* PC, FCanUnpause CanUnpauseDelegate = FCanUnpause())

Parameters

Name Type Description Default
PC APlayerController* The PlayerController requesting the pause. Used to verify admin or pause privileges.
CanUnpauseDelegate FCanUnpause Optional delegate called each frame to test whether the pause condition has cleared. When the delegate returns true the pause is lifted. FCanUnpause()

Return Type

bool

Example

Pause game when a menu opens C++
void AMyPlayerController::OpenPauseMenu()
{
    AMyGameMode* GM = GetWorld()->GetAuthGameMode<AMyGameMode>();
    if (GM)
    {
        // Pause until CloseMenu calls ClearPause
        GM->SetPause(this, FCanUnpause::CreateUObject(this,
            &AMyPlayerController::IsMenuClosed));
    }
}

Version History

Introduced in: 4.14

Version Status Notes
5.6 stable

Feedback

Was this helpful?

Suggest an edit

Select a field above to begin editing.