Node

    Base class for all scene objects.

    Node.swift:54
    class Node

    Nodes are Godot’s building blocks. They can be assigned as the child of another node, resulting in a tree arrangement. A given node can contain any number of nodes as children with the requirement that all siblings (direct children of a node) should have unique names.

    A tree of nodes is called a scene. Scenes can be saved to the disk and then instantiated into other scenes. This allows for very high flexibility in the architecture and data model of Godot projects.

    Scene tree: The SceneTree contains the active tree of nodes. When a node is added to the scene tree, it receives the notificationEnterTree notification and its _enterTree callback is triggered. Child nodes are always added after their parent node, i.e. the _enterTree callback of a parent node will be triggered before its child’s.

    Once all nodes have been added in the scene tree, they receive the notificationReady notification and their respective _ready callbacks are triggered. For groups of nodes, the _ready callback is called in reverse order, starting with the children and moving up to the parent nodes.

    This means that when adding a node to the scene tree, the following order will be used for the callbacks: _enterTree of the parent, _enterTree of the children, _ready of the children and finally _ready of the parent (recursively for the entire scene tree).

    Processing: Nodes can override the “process” state, so that they receive a callback on each frame requesting them to process (do something). Normal processing (callback _process(delta:), toggled with setProcess(enable:)) happens as fast as possible and is dependent on the frame rate, so the processing time delta (in seconds) is passed as an argument. Physics processing (callback _physicsProcess(delta:), toggled with setPhysicsProcess(enable:)) happens a fixed number of times per second (60 by default) and is useful for code related to the physics engine.

    Nodes can also process input events. When present, the _input(event:) function will be called for each input that the program receives. In many cases, this can be overkill (unless used for simple projects), and the _unhandledInput(event:) function might be preferred; it is called when the input event was not handled by anyone else (typically, GUI Control nodes), ensuring that the node only receives the events that were meant for it.

    To keep track of the scene hierarchy (especially when instantiating scenes into other scenes), an “owner” can be set for the node with the owner property. This keeps track of who instantiated what. This is mostly useful when writing editors and tools, though.

    Finally, when a node is freed with Object/free() or queueFree, it will also free all its children.

    Groups: Nodes can be added to as many groups as you want to be easy to manage, you could create groups like “enemies” or “collectables” for example, depending on your game. See addToGroup(_:persistent:), isInGroup(_:) and removeFromGroup(_:). You can then retrieve all nodes in these groups, iterate them and even call methods on groups via the methods on SceneTree.

    Networking with nodes: After connecting to a server (or making one, see ENetMultiplayerPeer), it is possible to use the built-in RPC (remote procedure call) system to communicate over the network. By calling rpc(method:) with a method name, it will be called locally and in all connected peers (peers = clients and the server that accepts connections). To identify which node receives the RPC call, Godot will use its NodePath (make sure node names are the same on all peers). Also, take a look at the high-level networking tutorial and corresponding demos.

    This object emits the following signals:

    Superclasses

    Citizens in SwiftGodot

    Conformances

    • protocol CustomStringConvertible

      A type with a customized textual representation.

    • protocol Equatable

      A type that can be compared for value equality.

    • protocol Hashable

      A type that can be hashed into a Hasher to produce an integer hash value.

    • protocol Identifiable<ID>

      A class of types whose instances hold the value of an entity with stable identity.

    • protocol VariantRepresentable

      Types that conform to VariantRepresentable can be stored directly in Variant with no conversion. These include all of the Variant types from Godot (for example GString, Rect, Plane), Godot objects (those that subclass SwiftGodot.Object) as well as the built-in Swift types UInt8, Int64 and Double.

    • protocol VariantStorable

      Types that conform to VariantStorable can be stored in a Variant and can be extracted back out of a Variant.

    Types

    Type members

    Instance members

    Show implementation details (10)

    Hide implementation details

    Subclasses