Pause / Unpause - A 3-Steps Way to do it.

So, since I was searching for a solution to this problem myself and unfortunately couldn’t really find anything, I put my thinking cap on and came up with a solution that feels clean and modular. I don’t want anyone else to have to waste their time searching for an efficient solution to this problem, which is why I’d like to share my approach here. I hope this helps some of you and/or gives you ideas in the right direction.

Problem: The pre-made “Set Game Paused” node comes with a few issues that those looking for a solution are surely familiar with.

Approach: We use “Set Global Time Dilation” and “Set Custom Time Dilation.”

Step 1 - We create an interface for our GameState with two functions that have no input or output: “Request Pause” and “Request Unpause,” and add this interface to the GameState:

Step 2 - In the GameState, we create the integer variable “Pause Requests.” (If we are in a menu that has paused the game, but from which we can open another submenu that should also pause the game, the pause should NOT end when this submenu is closed, since we are still in the menu. This counter helps us determine that.) We also create an EventDispatcher named “Game Pause Changed” with a Boolean input called “Paused”. We connect the interface functions as follows:

Step 3 - We create a new Actor Component and name it “AC_NotPausable”. Here, we bind the “Game Pause Changed” event from our GameState and set the custom time dilation based on the pause state. IMPORTANT! Use the “Delay until next tick” node; otherwise, you may encounter strange behavior with Timelines, for example:

And that’s basically it.

When we want to pause or unpause the game, we use the GameState interface functions “Request Pause” and “Request Unpause”. Since we’re working with a pause request counter there, menus that pause or unpause the game behave exactly as we’d expect. For actors that we want to continue running normally during the pause (animations, etc.), we simply add our “AC_NotPausable” component: