This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
0 votes

I am making an onready variable, and I need it to check for a node, however I also need it to check for the nodes duplicates. And since duplicates in Godot have a number after them I can't just do:

onready var x = get_parent().get_node("x")

So how can I also check for duplicates?

in Engine by (32 points)

1 Answer

0 votes

an easy way would be to use groups. Put your x-node in a group like "x_nodes". then get them with

var all_the_x_nodes = get_tree().get_nodes_in_group("x_nodes")

read about it here:

by (4,088 points)

Thanks very much, you seem to be answering all my questions :)

I was wondering if there is a way to do this without using groups, since calling a group requires a change in some other code which I dont want to change.

well ... in theory you can scan the tree for any instance.

do cou know the call getnodeor_null() with that you can try to get a node

for i to range(0,10):
    var node = get_node_or_null("x"+str(i))
    if node:
        do something( node )

Ah, it isn't quiet what I wanted but I'll figure something out. Thanks!

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 Frequently asked questions and 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 [email protected] with your username.