How to pause a node?

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

I want to know if there is any code to pause a node.
Example, I want when an animation of (AnimationPlayer) finishes
The “Player” node goes into pause mode, but I don’t know how to do it, please help.

:bust_in_silhouette: Reply From: Inces

There is a code to pause everything :

get_tree().paused = true

Pause in Godot means all process() and inputs() are held. If You only want to pause one node it is better to do this manually. Take a moment and think what do You mean by pausing a node - what do You really want it to stop ? Movement, its tasks, player control ? If its more than one thing I would introduce boolean variable “paused”, and I would add code to the beginning of every function You want stopped :

if paused = true :

This means that each of these functions will reach code below this sentence only in condition paused is false.
Finally, on AnimationEnded signal I would set paused to true. Of course there must some way to unpause player, You must design it wisely :slight_smile:

do children of that paused node pause too?

Delin | 2022-08-10 14:52

no, this above is custom pause example, it is not a built_in functionality of Godot. So it will only affect the script it is in, and functions it returns from. Again, You need to design what exact processes You want to stop for children nodes, and You can upgrade this code so it stops that too.

Inces | 2022-08-10 17:12

Oh my bad I misread your answer, I thought it was a built-in functionality

Delin | 2022-08-11 11:02

first sentence is a built in :

get_tree().paused = true

it pauses everything exept shaders. But You can set pasue_modeof chosen nodes to not be paused when tree is paused.

Inces | 2022-08-11 15:19

1 Like