Topic was automatically imported from the old Question2Answer platform.
Asked By
vonflyhighace2
Old Version
Published before Godot 3 was released.
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?
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.
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.