This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
0 votes

I'm running into an issue where scripts don't seem to be checking what other scripts inherit from properly. Here's my code:

Script A:

extends "res://Objects/Parents/"

func _ready():
    print("A: ",self is root_script)

Script B:

extends "res://Objects/Parents/"

func get_hit(other):
    print("B: ",other is root_script)

onready var root_script = get_script()

However, when I test this and run get_hit from Script B (with the node Script A as its argument), in the output I get:

A: True
B: False

Is there a proper way to test for inheritance that I'm not doing here?

Godot version 3.2.3.stable
in Engine by (31 points)

1 Answer

0 votes
Best answer

Nevermind, I figured out the problem.

get_script() returns the script of the child, if called from a parent that gets inherited by the child; I was expecting get_script() to always be the value of the parent instead of the value of the child, since it was only written in the parent and never called from the child.

Replacing get_script() with load("res://Objects/Parents/") did the job and it works as expected now.

by (31 points)
edited by
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.