+1 vote

It is probably something I am misunderstanding about inheritance, but when I do this:

extends Node
class_name Enemy

export var sprite_node : NodePath
var sprite

func _ready():
    sprite = get_node(sprite_node)

and then

extends Enemy
class_name AnEnemy

func _ready():
    print(sprite)

it just tells me that it can't find the node sprite even though I have referenced a node path from the inspector. Is it not possible to define Export in the base class, or am I not getting something here?

in Engine by (57 points)

1 Answer

+1 vote

Hi,
you are overwriting the _ready class where sprite gets assigned.
You have to call the base class manualy.

extends Enemy
class_name AnEnemy

func _ready():
    ._ready() #call the base class method first so sprite get assigned
    print(sprite)
by (4,044 points)
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 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 webmaster@godotengine.org with your username.