Nodes
Nodes are the building blocks in Godot.
Instancing
A node added to a scene by instancing and adding as a child:
model = slot_data.item_data.model.instantiate()
add_child(model)
Add and remove node from scene tree
A node needs to be linked to the scene tree to be visible and interactable.
add_child(MyNode)
remove_child(MyNode)
Removing from the scene tree doesn't remove it from memory!
A node in the scene tree is an active node. A node that is removed from the scene tree, but still kept in memory is an orphaned node.
Removing node from memory
A node is removed by freeing it:
get_node("NodeName").free()
Deletes the node immediately.
$NodeName.queue_free()
Deletes the node at the end of the frame. This is the recommended way!
Only change the visibility
To hide or show a node simply set its visible property.
self.visible = false
self.visible = true
The node is still processed and continues to act in the game!
To stop processing, you need to set the process mode:
# Disable:
var old_mode = self.process_mode
self.process_mode = ProcessMode.PROCESS_MODE_DISABLED
# Re-enable:
self.process_mode = old_mode
Quick delete
The quick way to delete an object from the scene is:
get_parent().remove_child(self) # first orphan self, making it not part of the scene
queue_free() # queue self for memory release.