This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
+4 votes

I'm trying to implement a respawning static object in 3D (it's an energy wall). For convenience I'd prefere to disable it on "death" and reinable it on respawn, rather than freeing it and reinstancing it later. I'm not sure how to go about this. I'm pretty certain that node.hide() only disables visibility and disabling process won't disable signals.

I can't find anything that might have the effect I'm looking for. Any suggestions?

in Engine by (76 points)

5 Answers

+8 votes

Apart from just hiding the object, you can also disable it by calling the set_process(false)function. Just bear in mind that if you disable a process of a node from within the node itself, you will have to reenable the process by calling set_process(true)from another script, should you decide to do that later. Generally speaking, it is good practice to enable and disable nodes from a master node. So dedicate a spawner object whose role is to activate and deactivate other nodes.

Another way would be to delete a node from the tree with remove_child() and reenter it when necessary, after you have kept its position in a variable

by (1,892 points)
edited by

I find that add_child is very expensive

Is this still true? It seems setting process_mode to Node.PROCESS_MODE_DISABLED or 4 does the trick too (if children have process_mode inherit).

+13 votes

The most generic way to disable a node entirely is to remove it from the tree temporarily, and store it somewhere so that you can put it back later. I'm just not sure if signals will turn off, maybe they remain.

Another way is to delete it entirely, and re-instance later.

Other more efficient solutions will switch only the relevant states, so it depends on the node and scripts it might have. You could want to:
- Hide it
- Turn off its physics shapes and layers so it no longer collides
- Stop any sound it might play
- Disconnect its signals, or add checks in its script
- set_process(false)
- set_physics_process(false)
- set_process_input(false) etc

That means the concept of "disabled" is highly specialized to what you actually want, so quite often you need to write that yourself.

by (29,510 points)

Is this still true? It seems setting process_mode to Node.PROCESS_MODE_DISABLED or 4 does the trick too (if children have process_mode inherit).

–1 vote

You can just set the pause property to true -> pause = true and visible = false. That makes it 'disabled'.

by (12 points)

There is no pause-property, only a pause_mode-property: You don't pause individual nodes, you pause the whole tree (using get_tree().paused = true). While it's true that you can define exceptions by setting the pause_mode to PAUSE_MODE_PROCESS, that's certainly not something you should use to disable just one node.

not actually becouse its collision shape is still there

+1 vote

If you right-click on a node to open the context menu, then choose "save branch as scene", once it has been converted you can now open the context menu again and turn on the option "load as placeholder". This will keep the scene in the tree, but won't perform any loading actions.

I use it to turn of big ticket items like landscapes (using zylann HeightMap) when I'm testing things I don't need the landscape for.

I haven't tried this yet, but I think once you're done testing you can open the context menu one last time after turning off 'load as placeholder', and choose "merge from scene", which theoretically converts it back into a basic node-subtree

by (28 points)
+1 vote

I use process_mode in tandem with showing/hiding nodes:
(Important is that child nodes' process_mode is set to inherit)

func disable_and_hide_node(node:Node) -> void:
    node.process_mode = 4 # = Mode: Disabled

func enable_and_show_node(node:Node) -> void:
    node.process_mode = 0 # = Mode: Inherit
by (61 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.