How to detect pause and unpause event?

I’m scripting a cheat system where input is only allowed when the game is paused. For that I use the pause boolean node. I want to clear a variable as soon as the game unpauses. Is there a way to detect an unpause event?

The best way would be to bind it to an input event, like a keypress, to unset the boolean, (or set it to false).

EDIT: Sorry, rereading your question, do you want an event listener that works like an OnUnPause?

Yea, an event listener should do the trick but I don’t know how. Googling for Unreal event listener gives me only results for dispatcher, though I’m new to unreal scripting so I really hope you have some advice for me.

This sounds like you need a Custom Event.

You can build one in the same place as you are currently setting the pause boolean to true.

Use a Flip-Flop node on the keypress to toggle between calling OnPause and OnUnpause. The custom event will fire.

NB: You may also need to do this, as by default, some buttons don’t respond when the game is paused, for obvious reasons. Click on the button you want to use for pausing in your blueprint and on the details panel on the right just tick the option “Execute when paused”.

1 Like