Inherited By: Viewport, Timer, CanvasLayer, EventPlayer, SoundRoomParams, Spatial, AnimationPlayer, EditorPlugin, ResourcePreloader, AnimationTreePlayer, SamplePlayer, InstancePlaceholder, StreamPlayer, CanvasItem, Tween
Base class for all the “Scene” elements.
- enter_tree ( )
- exit_tree ( )
- renamed ( )
- NOTIFICATION_ENTER_TREE = 10
- NOTIFICATION_EXIT_TREE = 11
- NOTIFICATION_MOVED_IN_PARENT = 12
- NOTIFICATION_READY = 13
- NOTIFICATION_FIXED_PROCESS = 16
- NOTIFICATION_PROCESS = 17 — Notification received every frame when the process flag is set (see set_process).
- NOTIFICATION_PARENTED = 18 — Notification received when a node is set as a child of another node. Note that this doesn’t mean that a node entered the Scene Tree.
- NOTIFICATION_UNPARENTED = 19 — Notification received when a node is unparented (parent removed it from the list of children).
- NOTIFICATION_PAUSED = 14
- NOTIFICATION_UNPAUSED = 15
- NOTIFICATION_INSTANCED = 20
- PAUSE_MODE_INHERIT = 0
- PAUSE_MODE_STOP = 1
- PAUSE_MODE_PROCESS = 2
Nodes can be set as children of other nodes, resulting in a tree arrangement. Any tree of nodes is called a “Scene”.
Scenes can be saved to disk, and then instanced into other scenes. This allows for very high flexibility in the architecture and data model of the projects.
SceneTree contains the “active” tree of nodes, and a node becomes active (receiving NOTIFICATION_ENTER_SCENE) when added to that tree.
A node can contain any number of nodes as a children (but there is only one tree root) with the requirement that no two children with the same name can exist.
Nodes can, optionally, be added to groups. This makes it easy to reach a number of nodes from the code (for example an “enemies” group).
Nodes can be set to “process” state, so they constantly receive a callback requesting them to process (do anything). Normal processing (_process) happens as fast as possible and is dependent on the frame rate, so the processing time delta is variable. Fixed processing (_fixed_process) happens a fixed amount of times per second (by default 60) and is useful to link itself to the physics.
Nodes can also process input events. When set, the _input function will be called with every input that the program receives. Since this is usually too overkill (unless used for simple projects), an _unhandled_input function is called when the input was not handled by anyone else (usually, GUI Control nodes).
To keep track of the scene hierarchy (specially when instancing scenes into scenes) an “owner” can be set to a node. This keeps track of who instanced what. This is mostly useful when writing editors and tools, though.
Finally, when a node is freed, it will free all its children nodes too.
Member Function Description¶
- void _enter_tree ( ) virtual
- void _exit_tree ( ) virtual
- void _fixed_process ( float delta ) virtual
Called for fixed processing (synced to the physics).
- void _input ( InputEvent event ) virtual
Called when any input happens (also must enable with set_process_input or the property).
- void _process ( float delta ) virtual
Called for processing. This is called every frame, with the delta time from the previous frame.
- void _ready ( ) virtual
Called when ready (entered scene and children entered too).
- void _unhandled_input ( InputEvent event ) virtual
Called when any input happens that was not handled by something else (also must enable with set_process_unhandled_input or the property).
- void _unhandled_key_input ( InputEvent key_event ) virtual
Called when any key input happens that was not handled by something else.
Add a child Node. Nodes can have as many children as they want, but every child must have a unique name. Children nodes are automatically deleted when the parent node is deleted, so deleting a whole scene is performed by deleting its topmost node.
The optional boolean argument enforces creating child node with human-readable names, based on the name of node being instanced instead of its type only.
Add a node to a group. Groups are helpers to name and organize group of nodes, like for example: “Enemies”, “Collectables”, etc. A Node can be in any number of groups. Nodes can be assigned a group at any time, but will not be added to it until they are inside the scene tree (see is_inside_tree).
- bool can_process ( ) const
Return true if the node can process.
Find a descendant of this node whose name matches
mask as in String.match (i.e. case sensitive, but ‘*’ matches zero or more characters and ‘?’ matches any single character except ‘.’). Note that it does not match against the full path, just against individual node names.
Return a children node by it’s index (see get_child_count). This method is often used for iterating all children of a node.
- int get_child_count ( ) const
Return the amount of children nodes.
- Array get_children ( ) const
- String get_filename ( ) const
Return a filename that may be containedA node can contained by the node. When a scene is instanced from a file, it topmost node contains the filename from where it was loaded (see set_filename).
- float get_fixed_process_delta_time ( ) const
Return the time elapsed since the last fixed frame. This is always the same in fixed processing unless the frames per second is changed in OS.
- Array get_groups ( ) const
- int get_index ( ) const
Get the node index in the parent (assuming it has a parent).
- String get_name ( ) const
Return the name of the Node. Name is be unique within parent.
Fetch a node. NodePath must be valid (or else error will occur) and can be either the path to child node, a relative path (from the current node to another node), or an absolute path to a node.
Note: fetching absolute paths only works when the node is inside the scene tree (see is_inside_tree). Examples. Assume your current node is Character and following tree:
Possible paths are:
- Node get_owner ( ) const
Get the node owner (see set_owner).
- Node get_parent ( ) const
- NodePath get_path ( ) const
Return the absolute path of the current node. This only works if the current node is inside the scene tree (see is_inside_tree).
Return the relative path from the current node to the specified node in “node” argument. Both nodes must be in the same scene, or else the function will fail.
- int get_pause_mode ( ) const
- int get_position_in_parent ( ) const
- float get_process_delta_time ( ) const
Return the time elapsed (in seconds) since the last process callback. This is almost always different each time.
- bool get_scene_instance_load_placeholder ( ) const
- SceneTree get_tree ( ) const
- Object get_viewport ( ) const
Return true if the “node” argument is a direct or indirect child of the current node, otherwise return false.
- bool is_fixed_processing ( ) const
Return true if fixed processing is enabled (see set_fixed_process).
Return true if “node” occurs later in the scene hierarchy than the current node, otherwise return false.
- bool is_inside_tree ( ) const
- bool is_processing ( ) const
Return whether processing is enabled in the current node (see set_process).
- bool is_processing_input ( ) const
Return true if the node is processing input (see set_process_input).
- bool is_processing_unhandled_input ( ) const
Return true if the node is processing unhandled input (see set_process_unhandled_input).
- bool is_processing_unhandled_key_input ( ) const
Move a child node to a different position (order) amongst the other children. Since calls, signals, etc are performed by tree order, changing the order of children nodes may be useful.
- void print_stray_nodes ( )
- void print_tree ( )
Print the scene to stdout. Used mainly for debugging purposes.
- void propagate_notification ( int what )
Notify the current node and all its children recursively by calling notification() in all of them.
- void queue_free ( )
- void raise ( )
Move this node to the top of the array of nodes of the parent node. This is often useful on GUIs (Control), because their order of drawing fully depends on their order in the tree.
- void remove_and_skip ( )
Remove a node and set all its children as children of the parent node (if exists). All even subscriptions that pass by the removed node will be unsubscribed.
- void remove_child ( Node node )
Remove a child Node. Node is NOT deleted and will have to be deleted manually.
- void remove_from_group ( String group )
Remove a node from a group.
Replace a node in a scene by a given one. Subscriptions that pass through this node will be lost.
- void set_filename ( String filename )
A node can contain a filename. This filename should not be changed by the user, unless writing editors and tools. When a scene is instanced from a file, it topmost node contains the filename from where it was loaded.
- void set_fixed_process ( bool enable )
Enables or disables node fixed framerate processing. When a node is being processed, it will receive a NOTIFICATION_PROCESS at a fixed (usually 60 fps, check OS to change that) interval (and the _fixed_process callback will be called if exists). It is common to check how much time was elapsed since the previous frame by calling get_fixed_process_delta_time.
- void set_name ( String name )
Set the name of the Node. Name must be unique within parent, and setting an already existing name will cause for the node to be automatically renamed.
- void set_owner ( Node owner )
Set the node owner. A node can have any other node as owner (as long as a valid parent, grandparent, etc ascending in the tree). When saving a node (using SceneSaver) all the nodes it owns will be saved with it. This allows to create complex SceneTrees, with instancing and subinstancing.
- void set_pause_mode ( int mode )
- void set_process ( bool enable )
Enables or disables node processing. When a node is being processed, it will receive a NOTIFICATION_PROCESS on every drawn frame (and the _process callback will be called if exists). It is common to check how much time was elapsed since the previous frame by calling get_process_delta_time.
- void set_process_input ( bool enable )
Enable input processing for node. This is not required for GUI controls! It hooks up the node to receive all input (see _input).
- void set_process_unhandled_input ( bool enable )
Enable unhandled input processing for node. This is not required for GUI controls! It hooks up the node to receive all input that was not previously handled before (usually by a Control). (see _unhandled_input).
- void set_process_unhandled_key_input ( bool enable )
- void set_scene_instance_load_placeholder ( bool load_placeholder )