+1 vote

I made an overaching game object that handles a lot of the game's big functions including the pause function.

func _process(delta):
var k_pause = Input.is_action_pressed("pause")

if !get_tree().is_paused() and can_pause and k_pause:
    get_tree().set_pause(true)
elif get_tree().is_paused() and k_pause:
    get_tree().set_pause(false)

As a simple object, it works as intended- taking the game in and out of pause- because I set the Pause mode to "Process". After learning about Autoload and singletons, I made the game object autoloaded. Thing is, although the game object is always around as intended, when it falls into the Pause state, it cannot get out. It remains paused even though the object is supposed to Process while the tree is paused.

I've looked at how the game handles roots and SceneTrees, but I can't figure out why my game singleton gets paused when it activates pause mode.

in Engine by (28 points)

1 Answer

+1 vote
Best answer

When using set_pause_mode( int mode ) in your singleton, did you use the integer constant for PAUSE_MODE_PROCESS ?
PAUSE_MODE_INHERIT = 0 PAUSE_MODE_STOP = 1 PAUSE_MODE_PROCESS = 2

Just tested this on an autoloaded singleton and can confirm it works:

var g = 0

func _ready():
    self.set_pause_mode(2) # Set pause mode to Process
    set_process(true)

func _process(delta):
    g += delta
    print(str(g))
by (1,294 points)
selected by

When using setpausemode( int mode ) in your singleton, did you use the integer constant for PAUSEMODEPROCESS ?

I didn't use setpausemode in the _ready event for the *game* object because I didn't know I had to. I'm still learning how singletons work and how they're different from regular scenes and objects.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.

Categories