+1 vote

var nodeA = sceneA.instance()

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

in Engine by (264 points)
edited by

2 Answers

+5 votes
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():
by (1,098 points)
0 votes

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.

by (341 points)

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

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.