How get last child added

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By lalel345

how to always get the last child of a node independently of the number of children.
Even if the number of children is higher or lower, always take the last one, with the get_child() method I take a specific one but if I add more, I can’t get the last one

:bust_in_silhouette: Reply From: jgodfrey

I think the node indices are stable and predictable. If that’s the case, you should be able to get the number of children associated with a parent via get_child_count() and then reference the last one via its index using get_child(). So, essentially this:

var last_child = $Parent.get_child($Parent.get_child_count()-1)
1 Like