Yoav
Yoav

Reputation: 305

Rotation in parent class not working on inheriting class in godot

I have a parent class (not node):

class_name Dragon

extends Area2D

@onready var dragon_frames = $DragonFrames

func _ready():
    rotation += deg_to_rad(60)

The inheriting class:

class_name FireDragon

extends Dragon

func _ready():
    dragon_frames.play("flying_red_dragon")

The FireDragon node is not rotating. The animation works fine.
This works as expected:

class_name FireDragon

extends Dragon

func _ready():
    dragon_frames.play("flying_red_dragon")
    rotation += deg_to_rad(60)

Do some attributes not work with inheritance?
I'm using godot 4.2.1

Upvotes: 1

Views: 44

Answers (1)

M. R. M.
M. R. M.

Reputation: 653

Your code is correct but for version 3.x,
_ready() is no longer auto called in version 4.x

You'll have to manually invoke _ready() like this:

class_name FireDragon
extends Dragon

func _ready():
    super() # or `super._ready()`
    dragon_frames.play("flying_red_dragon")

Upvotes: 1

Related Questions