Table of Contents
- Overrideable functions (
- Create and delete a node
- Where should I check for user input?
- Which class should I use for script-only nodes?
Overrideable functions (
_process(), …) discussioin
func _enter_tree(): # When the node enters the _Scene Tree_, it becomes active # and this function is called. Children nodes have not entered # the active scene yet. In general, it's better to use _ready() # for most cases. pass func _ready(): # This function is called after _enter_tree, but it ensures # that all children nodes have also entered the _Scene Tree_, # and became active. pass func _exit_tree(): # When the node exits the _Scene Tree_, this function is called. # Children nodes have all exited the _Scene Tree_ at this point # and all became inactive. pass func _process(delta): # This function is called every frame. pass func _physics_process(delta): # This is called every physics frame. pass
- Adding nodes to
- Child nodes are always added after their parent node.
_enter_tree()is called before adding child nodes
- a left node is added,
_enter_tree()will be called. And then
- Once all child nodes' finish calling their
_ready(), the non-left nodes'
_ready()will be called.
- Once all nodes have been added to the
_physics_process()are called every frame. Same as other engines.
_input()is called only there are some input events.
_unhandled_input()to catch input events which are not processed by other components, like buttons.
Create and delete a node howto
Node get_node ( NodePath path ) const
pathcan be either relative or absolute(in the scene tree).
null instanceif the path does not exist.
/root /root/Character /root/Character/Sword /root/Character/Backpack/Dagger /root/MyGame /root/Swamp/Alligator /root/Swamp/Mosquito /root/Swamp/Goblin
If the current node is
Character, following calls are valid:
get_node("Sword") get_node("Backpack/Dagger") get_node("../Swamp/Alligator") get_node("/root/MyGame")
get_node() is really frequently used, it has a shorthand
$<nodepath> returns the node at the relative path from this node, or returns
null if the node is not found. For example,
$AnimatedSprite, or double-quoted, like
- It's useful to organize nodes.
- A node can be in any number of groups.
Where should I check for user input?
- Generally, use
- If your input is directly altering a
Which class should I use for script-only nodes? discussion
It is not explicitly mentioned, but most of tutorials use just
Node class for script-only nodes, regardless of 2D or 3D.
Rect2 get_viewport_rect ( ) const
Get the viewport’s boundaries as a