Skip to content

Instantly share code, notes, and snippets.

@sephirot47
Last active January 5, 2023 11:34
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sephirot47/6d7ccbeccd103eeec649 to your computer and use it in GitHub Desktop.
Save sephirot47/6d7ccbeccd103eeec649 to your computer and use it in GitHub Desktop.
UE4 Pause - Resume Game
/*
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
*/
@leopoldoizquierdo
Copy link

Definitely, not all heroes have capes, Thank you so much!

@ItsShoRyuKen
Copy link

Thanks a lot, saved me a lot of time

@neo-luna
Copy link

Thanks you!

@junka030
Copy link

junka030 commented May 6, 2021

Thanks!!

@mdragon159
Copy link

Thanks a ton!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment