Hi Y'all,
maybe you can help me figuring out how to pause/freeze the entire run of the game for 10 seconds.
I tried using await get_tree().create_timer(10).timeout but it just doesn't work.
thank you,
Godot 4: Freeze/ Pause/ Sleep game for 10 seconds
- Edited
Create a node somewhere that has process_mode set to Always. In a script on this node add get_tree().paused = true (triggered by whatever triggers the pause) and start a 10 second timer that sets paused to false again on timeout.
matanits1 was your timer set to one-shot?
The other option is to check the system time with a singleton outside of the main scene tree that keeps processing (pause_mode = always) and then check the time elapsed vs the time the game started the pause.
var _elapsed = 0 ### holder for value you will check
var _startTime : int = 0 ## holder for "start time" which checks system's "atomic" clock
const _endTime = 10000 ## 10 * 1000 milliseconds = 10 seconds
## tie this to your "pause" function, as this will log your "start" on the timer
func _timeLog():
if _startTime == 0:
_startTime = get_ticks_msec()
## then if pausing happens, we watch the atomic clock, and "empty" the value when done
func _process(delta):
if get_tree().paused == true:
_elapsed = get_ticks_msec() ## elapsed time updates each frame
else:
_elapsed = 0
## check start time vs how much has passed then when it hits the target time, unpause
var _difference = _elapsed-_startTime
if _difference >= _endTime:
_startTime = 0
get_tree().paused == false
Thank you so much!
I will be sure trying this soon and let you know how it goes!