0 votes

How do I get a node by searching it.

onready var objectA = get_node("blocksA")

I need to find it because the position and child could be different every time.
Thanks for help.

asked Jun 7, 2019 in Engine by usurun (322 points)
edited Jun 7, 2019 by usurun
var currentObj = get_tree().get_nodes_in_group ("group")[0]

1 Answer

+1 vote

get_node returns exactly one node specified by the path parameter, not all nodes matching this name. To find all nodes matching a certain criteria, you could assign them to a group (e.g. "group_blocksA") and access them with

onready var objects_A = get_nodes_in_group ("group_blocksA")

(see https://docs.godotengine.org/en/3.1/classes/class_scenetree.html#class-scenetree-method-get-nodes-in-group )

answered Jun 7, 2019 by Thomas Karcher (1,046 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.