how to check if a node is an instance of a scene?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By alexzheng
:warning: Old Version Published before Godot 3 was released.

var nodeA = sceneA.instance()

how can I check whether the nodeA is an instance of sceneA?

:bust_in_silhouette: Reply From: eska
if nodeA.get_filename() == sceneA.get_path():

That should do it, calling get_filename() on an instantiated scene’s root node returns the path to the scene file by default.

If you want to check child nodes as well, use get_owner(), which in effect returns the root node when called on child nodes or null otherwise:

var root
if nodeA.get_owner():
    root = nodeA.get_owner()
    root = nodeA
if root.get_filename() == sceneA.get_path():
:bust_in_silhouette: Reply From: 807

Ok, I´m not sure of that, but probably is a valid case to “extends” keyword (or “is” in godot 3.0) . Can you try?:

if nodeA extends sceneA: 
  print ("it works")

Never use extends for that, but who knows.

unable to do that as PackedScene is not a class. It will give error more less like this : right operand of the 'is' is not a class

Heizky | 2020-06-02 15:51