Export vars from superclass result in null values in subclass

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By peterhoglund

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?

:bust_in_silhouette: Reply From: klaas

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)