I want to be able to detect if a given node has a given script type attached.
Suppose I have a 2D Sprite node named "mySprite" with a script file named "MySprite.gd"
In the parent of mySprite's script I do
const MySprite = preload("/path/to/MySprite.gd")
var spr = get_node("mySprite")
print( spr extends MySprite )
I thought this would be True but this results in False.
If I try printing spr:
print( str(spr) )
This results in [Sprite:588] instead of [MySprite:...]
I found out about get_script() however, I still can't make it work:
print(spr.get_script() == MySprite)
print(spr.get_script() extends MySprite)
All of the above print "False"
However if I do:
The output source code is identical.
I found out the problem. I tried doing
Turns out the result is:
The paths are different when using absolute paths and relative paths! (The mySprite node uses a relative path). This causes the script object instances to be different. If I change it to both use relative paths then the script object becomes the same instance. I believe this is a bug which could be causing unnecessary loading of resources multiple times.
Note: bug filed here: