Singleton object pausing when it shouldn't be

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

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.

:bust_in_silhouette: Reply From: ericdl

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))

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

I didn’t use set_pause_mode 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.

DoubleCakes | 2016-11-14 19:35