How to loop over all children of a node in the main scene?

Godot Version

4.3

Question

I just started learning Godot so I’m not sure how to phrase this question. I have a node that I want to use as a checkpoint for the character to move to when the player clicks it, like so:
image

In my main scene, I have one checkpoint that is the destination, which has a couple child checkpoints that the character is supposed to path through, like this:
image

Now I want to loop over all the child checkpoints and tell the character to move to them one after the other. The thing is, if I call Checkpoint.get_children(), it returns the texture, which is of course the checkpoints children in its own scene. But what I want is a list of all the checkpoints children in the main scene. How can I achieve this?

If Destiantion has the script, then this node must be the root node.
In this case, you can loop through the children like this:

for checkpoint in get_children():
    print(checkpoint.name)

If not then you need a handle, either by
var destiantion = get_node(THE_NODE_PATH)
or by access of its Unique Name

for checkpoint in %Destiantion.get_children():
    print(checkpoint.name)
2 Likes

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.