Enabling and disabling objects during runtime

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By vonflyhighace2
:warning: 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?

:bust_in_silhouette: Reply From: whooshfrosted

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

For GUI items I use show()/hide() and sometimes set_disabled() with set_opacity().

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


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

vinod | 2017-03-26 10:39

:bust_in_silhouette: Reply From: eons

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.

:bust_in_silhouette: Reply From: vinod

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.

That’s it, brilliant!

ville | 2018-04-15 13:26