+2 votes

Is it possible to enable and disable objects like how Unity3D does during runtime. Instead of deleting and instancing your able to just turn off/disable an object/script/resource or whatever. If not is there any work around?

in Engine by (270 points)

3 Answers

+1 vote

There's a Node function called setpausemode(), but no comment on how it is used. The one I use is set_process.

For GUI items I use show()/hide() and sometimes setdisabled() with setopacity().

The underscores have been removed from some of the above functions for some reason. I don't know why.

by (249 points)
edited by
set_pause_mode

This changes the behaviour of the node when a global pause occurs. Can be set in the editor inspector.

+4 votes

Sadly, no, but you can remove and re-insert on the tree.


Instanced scenes can be marked as placeholder in the editor (the instance node drop down menu), so you can add them to the tree but won't appear until you activate them by instancing (this can work like a "disabled" GameObject for testing too).

Is like a PackedScene but with the instance location already placed on the tree, then instance the node with replace_by_instance.

May be possible to replace it back to a InstancePlaceholder but not sure.


More options, add many Node as placeholder, then replace_by the node/scene you want, disable it by replacing it back by a Node (Node2D/Spatial if you want to keep the position), you will need to set again all the signals and groups.


Pause mode may work but is global, is better to use to pause everything except a few nodes (like a pause menu).


All the methods that affect the tree (with node replacement/re-insertion) will execute _ready (godot 2-) and _enter_tree again on the node when re-entering.

by (7,894 points)
+2 votes

You need to write your own logic for enabling and disabling your game object.
For example,write a function which disables the collision of the physics bodies, set the physics body velocity to zero and hide the sprites to disable a game object.

by (750 points)

That's it, brilliant!

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 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 webmaster@godotengine.org with your username.