How to check if the node is in the scene?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Celimp
If the node is in the scene:
    do something
:bust_in_silhouette: Reply From: Celimp

Figured it out by myself and quite quickly.
You can use has_node() to see if it exists in a given path.

Would you mind expanding on how to use has_node() to see if self is ready?

Bruno Ely | 2019-06-19 22:50

You need to specify the node’s name.

 if get_tree().root.get_child(0).has_node('enemy/spatial/grenade')

Actually I’m searching for other way to do that, like to check if the tree have a node without writting full name, because multiple enemies get numbers at ending to clone they.
I just want to check if tree has ANY enemy

S4_Yuuki | 2022-04-12 01:56

:bust_in_silhouette: Reply From: Luiz Carlos L. G. de

It’s too late, but I’ll answer in case anyone ends up here.

The Node class has a method is_inside_tree. That’s it.