Last active
January 5, 2023 11:34
-
-
Save sephirot47/6d7ccbeccd103eeec649 to your computer and use it in GitHub Desktop.
UE4 Pause - Resume Game
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
There's a function you can call to pause / resume the game in UE4: | |
UGameplayStatics::SetGamePaused(GetWorld(), true); //true = paused, false = resume | |
So you would do something like this: | |
*/ | |
void Pause() | |
{ | |
if(myGamePaused) UGameplayStatics::SetGamePaused(GetWorld(), false); | |
else UGameplayStatics::SetGamePaused(GetWorld(), true); | |
} | |
/* | |
But there's a problem, if the game is paused, it also pauses the object responsible for pausing/resuming the game. Because of this, you won't be able to resume the game. There's a workaround though... | |
The actual problem here, is that the PlayerController stops processing its inputs, so your pause manager won't be able to catch them and unpause the game. The solution is to specify the input of the pause key to keep catching the events when the game is paused, and this can be done like this: | |
*/ | |
FInputActionBinding& toggle = InputComponent->BindAction("Pause", IE_Pressed, this, &AMyActor::Pause); | |
toggle.bExecuteWhenPaused = true; //EVEN THOUGH THE GAME IS PAUSED, CATCH THIS EVENT !!!! | |
/* | |
And now the method Pause will execute even if the game is paused so this means you will be able to unpause the game correctly. YAAAAY :D | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks!!