set_process()
does work as intended. Here's an example:
Create a new scene with this structure:
Node2D
ButtonToggle (button node)
Attached the following script to the Node2D
extends Node2D
var time = 0
func _process(delta):
time += delta
print(time)
func _on_ButtonToggle_pressed():
set_process(!is_processing())
Finally, wire the Button
's pressed()
event to the script's _on_ButtonToggle_pressed()
handler.
Run the scene and note how pressing the button toggles the process state of the node and starts/stops executing the code in _process()
If it's not working in your project, I'd say the problem is in your code. In that case, you'll need to post the relevant code to get more assistance.