How do I pause ALL the nodes?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Unityfugee

Hello,

I pause the game using

get_tree().paused

but I noticed that some nodes aren’t getting paused - specifically the nodes that aren’t initially present in the scene tree and get instanced at runtime.

Is there a way to update get_tree() to pause all the new nodes so I don’t have to go in every prefab and write a script to set it to PAUSE_MODE_STOP?

Thank you.

:bust_in_silhouette: Reply From: klaas

Hi,
if the pause mode of a node is “inherit” it should stop when the parent stops.

are you sure that non of the parents are set to “process”?

I confirm all the nodes are set to inherit

Unityfugee | 2021-07-13 19:34

Can you provide some code? or screenshots of your tree layout?

klaas | 2021-07-13 19:44

Here’s my tree layout :
┖╴Spatial
┠╴ATH
┃ ┠╴HBoxContainer
┃ ┃ ┠╴Gaz
┃ ┃ ┠╴Frein
┃ ┃ ┖╴Embrayage
┃ ┠╴Dir
┃ ┠╴Compte-Tours
┃ ┃ ┠╴Contact
┃ ┃ ┠╴Aiguille
┃ ┃ ┖╴Rapport
┃ ┖╴Tachy
┃ ┠╴Kmh
┃ ┖╴Vitesse
┠╴Joueur
┠╴StaticBody
┃ ┖╴CollisionShape
┃ ┖╴MeshInstance
┠╴StaticBody2
┃ ┖╴CollisionShape
┃ ┖╴MeshInstance
┠╴Voiture
┃ ┠╴Chassis
┃ ┃ ┠╴Collision 1
┃ ┃ ┃ ┠╴Carrosserie
┃ ┃ ┃ ┠╴Roue Av G
┃ ┃ ┃ ┠╴Roue Av D
┃ ┃ ┃ ┠╴Roue Ar G
┃ ┃ ┃ ┖╴Roue Ar D
┃ ┃ ┠╴Collision 2
┃ ┃ ┠╴Son Moteur
┃ ┃ ┃ ┠╴Ralenti
┃ ┃ ┃ ┠╴Ralenti Haut
┃ ┃ ┃ ┠╴Charge Bas
┃ ┃ ┃ ┠╴Charge Haut
┃ ┃ ┃ ┖╴Démarreur
┃ ┃ ┖╴Klaxon
┃ ┠╴ColorRect
┃ ┃ ┖╴Debug
┃ ┠╴@@2
┃ ┠╴Roue
┃ ┃ ┠╴Collision roue
┃ ┃ ┖╴Position Roue
┃ ┃ ┖╴Mesh
┃ ┃ ┖╴Mesh Jante
┃ ┃ ┖╴Mesh Pneu
┃ ┠╴Fumee
┃ ┃ ┖╴Son Derapage
┃ ┠╴@@3
┃ ┠╴@Roue@4
┃ ┃ ┠╴Collision roue
┃ ┃ ┖╴Position Roue
┃ ┃ ┖╴Mesh
┃ ┃ ┖╴Mesh Jante
┃ ┃ ┖╴Mesh Pneu
┃ ┠╴@Fumee@5
┃ ┃ ┖╴Son Derapage
┃ ┠╴@@6
┃ ┠╴@Roue@7
┃ ┃ ┠╴Collision roue
┃ ┃ ┖╴Position Roue
┃ ┃ ┖╴Mesh
┃ ┃ ┖╴Mesh Jante
┃ ┃ ┖╴Mesh Pneu
┃ ┠╴@Fumee@8
┃ ┃ ┖╴Son Derapage
┃ ┠╴@@9
┃ ┠╴@Roue@10
┃ ┃ ┠╴Collision roue
┃ ┃ ┖╴Position Roue
┃ ┃ ┖╴Mesh
┃ ┃ ┖╴Mesh Jante
┃ ┃ ┖╴Mesh Pneu
┃ ┖╴@Fumee@11
┃ ┖╴Son Derapage
┠╴Circuit
┃ ┠╴Mesh Circuit
┃ ┖╴Collision Circuit
┠╴StaticBody3
┃ ┖╴CollisionShape
┃ ┖╴MeshInstance
┠╴StaticBody4
┃ ┖╴CollisionShape
┃ ┖╴MeshInstance
┠╴StaticBody5
┃ ┖╴CollisionShape
┃ ┖╴MeshInstance
┠╴StaticBody6
┃ ┖╴CollisionShape
┃ ┖╴MeshInstance
┖╴Caméra
┖╴Cam

The car’s wheels (“Roue”) are instanced on runtime. I pause with

func _process(delta):
    if Input.is_action_just_pressed("ui_cancel"):
        get_tree().paused = !get_tree().paused

Unityfugee | 2021-07-13 20:11

that does not provide much insight

maybe you want to debug this issue with the notification NOTIFICATION_PAUSED

Object — Godot Engine (stable) documentation in English

try to debug_print something on NOTIFICATION_PAUSED

klaas | 2021-07-13 20:23

On further inspection, all of the scripts are still running when pausing unless manually set to stop. I don’t know what to do

Unityfugee | 2021-07-13 20:52

maybe your pause code doesnt work as expected.

Try to breakpoint after you set paused

var tree = get_tree() # to inspect the tree
breakpoint

then check out the scenetree

klaas | 2021-07-13 20:55

Done
enter image description here

Nothing happens when I click on “tree”

Unityfugee | 2021-07-13 21:16

you have to click the object id to get the inspector for the tree

klaas | 2021-07-13 21:26

I think it’s bugged, it displays for like 1 frame in the inspector then nothing

Unityfugee | 2021-07-13 21:28

I just downloaded the latest version
Here’s the tree debug info:
enter image description here

Unityfugee | 2021-07-13 22:27

Nevermind I fixed it

Unityfugee | 2021-07-13 22:55

:bust_in_silhouette: Reply From: Unityfugee

Nevermind, I fixed it : I was running the pause script on the root node, which was set to process mode. All its childern are set to inherit mode, so they were running in process mode and were not pausing correctly.

Now, I’ve set the root node back to inherit mode and moved the pause code to a separate node and it now seems to be working correctly.