Pause function fail

Godot Version

4.2.1

Question

I have a Pause function that is failing to work, I have the function in an autoload. and i have the nodes i want to pause in a “Pausable” group. when i press my action key, I get my print output to confirm its pressed and also get the output to tell me its got the nodes, but nothing pauses.

my Autoloaded code,

extends Node2D

var missHit = false
var currentTanks = 0

var maxHealth = 1000
var minHealth = 0

var health:int = 1000
var score:int = 0
var timeSurvived:int = 0

func set_pause(pause: bool):
var nodes = get_tree().get_nodes_in_group(“Pausable”)
for node in nodes:
node.set_process(!pause)
node.set_physics_process(!pause)
if node == null:
print(“Cant get Nodes”)
else:
print(“Got Nodes”)

func _process(delta):
if Input.is_action_just_pressed(“pause”):
print(“Pause pressed”)
set_pause(true)
if Input.is_action_just_pressed(“unpause”):
print(“Pause pressed”)
set_pause(false)

if health > maxHealth:
health = maxHealth
if health < minHealth:
health = minHealth

Maybe you need this?

func _ready():
	process_mode = Node.PROCESS_MODE_PAUSABLE

I’ve changed my script to use,

func set_pause(pause):
var nodes = get_tree().get_nodes_in_group(“Pausable”)
for node in nodes:
node.get_tree().paused = (!pause)
node.get_tree().paused = (!pause)
if node == null:
print(“Cant get Nodes”)
else:
print(“Got Nodes”)

this now pauses, but will not unpause, using this ?

func _process(delta):
if Input.is_action_just_pressed(“pause”):
print(“Pause pressed”)
set_pause(true)
if Input.is_action_just_pressed(“unpause”):
print(“Pause pressed”)
set_pause(false)

Okay, I’ve now found that although the node containing this script is set to process always, it was not processing after the pause, adding this line, fixed the issue.

func _ready():
process_mode = Node.PROCESS_MODE_ALWAYS

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.