FantasyRun/utils.gd
2024-09-30 20:50:05 -07:00

18 lines
560 B
GDScript

extends Node
func find_first_node_of_type(node: Node, type: Variant) -> Node:
for child in node.get_children():
if is_instance_of(child, type):
return child
return null
func get_nodes_of_class(node: Node, type: Variant, include_internal: bool = false) -> Array[Variant]:
var nodes: Array[Variant] = []
for child in node.get_children(include_internal):
if is_instance_of(child, type):
nodes.append(child)
elif child.get_child_count(include_internal) > 0:
nodes.append_array(get_nodes_of_class(child, type, include_internal))
return nodes