Material Box

Material Box

WEB Design & Material Images

Godot - Search for nodes

Godot

How to search for child or parent nodes in Godot GDScript.
Using other node reference methods like get_node() is faster, and search is often unnecessary for many cases needing child or parent nodes.


Can search all descendant nodes for a node using find_children().
find_children() returns Array, and returns empty Array if no matching nodes found.

var nodes = find_children("NodeName")
print(nodes.size())

In pattern matching, "*" matches 0 or more characters.
"?" matches a single character.

var nodes = find_children("NodeNam*")
print(nodes.size())

var nodes = find_children("NodeNam?")
print(nodes.size())

Can use find_parent() to search for parent nodes.
find_parent() returns Array, and returns empty Array if no matching nodes found.

var nodes = find_parent("NodeName")
print(nodes.size())

Godot

TitleGodot - Search for nodes

CategoryGodot

Created

Update

AuthorYousuke.U