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.

in Engine by (344 points)
edited by
var currentObj = get_tree().get_nodes_in_group ("group")[0]

1 Answer

+2 votes

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 )

by (1,744 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.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.