create_timer() is unaffected by set_pause(), what should I do?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By mateusak
:warning: Old Version Published before Godot 3 was released.

If you start the timer, pause, wait, unpause, the action that would otherwise still be waiting will be executed instantly. Thats because pausing the game does not affect the created timers. What can I do about it? Is this a bug?

Hmmm, strange. For me, the timer is also paused and everything works as expected. I use Godot 2.1.
The behaviour that you described I would expect if Pause Mode of the timer is set to process.

lukas | 2017-01-27 10:05

Oh, no, that’s not it. I’m not talking about the node Timer, no. In Godot 2.2 branch there’s the method create_timer(seconds) available. You can use yield(get_tree().create_timer(seconds), "timeout") to pause a piece of code until the timer finishes. The problem is, this method still runs while paused.

mateusak | 2017-01-27 14:40

:bust_in_silhouette: Reply From: mateusak

Forget it, it’s a bug :slight_smile:
Hopefully 3.0 will come soon, can’t wait!

:bust_in_silhouette: Reply From: jjmontes

In current versions, you can create a SceneTreeTimer that stops during pause using the parameter “pause_mode_process”:

await target.ToSignal(GetTree().CreateTimer(seconds, false), "timeout");

or in GDScript:

yield(get_tree().create_timer(seconds, false), "timeout")

The default pause_mode_process=true creates timers that do not stop during pause.

Method reference: SceneTree — Documentación de Godot Engine (4.x) en español