Skip to reading
GDScript Programming & Godot

36. Nodes, parents, paths and ownership

Edition 0.86.4.1 HF1

0.86.4.1 Hotfix 1 edition. Earlier lessons and screenshots retain their original version context; revised references and supplements describe the newer behavior.

Download PDFView PDF page
Code example
func run() -> bool:
    var marker := Node.new()
    marker.name = "TutorialMarker"
    add_child(marker)
    var found: Node = get_node_or_null("TutorialMarker")
    var correct: bool = found == marker
    marker.queue_free()
    return correct

A Node belongs to one parent. add_child places it in the tree; queue_free schedules its deletion. Use get_node_or_null when absence is acceptable. A leading slash is an absolute path from the SceneTree root; relative paths begin at the calling node.

A PCA script is parented under the script engine, not under the door that called it. $Mesh means a child of the script node. It does not search the rendered door model. %UniqueName depends on Godot scene ownership and a unique-name setup, not a PCA record ID.

Node.owner controls what can be included when packing a Godot scene. It is not the same as parent, PCA’s this, inventory ownership or the active player. For runtime-only nodes, a correct parent/lifetime is usually the first concern.

Page 45 of 378Permalink
Go to page