+2 votes

I have a general enemy class (parent), and a enemy type (child). The parent class has a ready function which calls some functions, and the child's _ready function initializes some variables, and calls the parents _ready function. Here's a example code


extends KinematicBody2D
class_name Enemy
func _ready():


extends Enemy
func _ready():

I was expecting the output as:

But what I get is:

Even when I don't call the parents _ready from child I still get:

Where I think I should be getting child only. As I am overriding the parents _ready()

I need to call the parents _ready after childs _ready() is called only once But somehow parent's _ready gets called before childs even if I override it.

I tried printing objects that are calling the _ready() by
print("parent:"+str(self)) and print("parent:"+str(self))
Then I see that the functions are called by the same object.
Heres the output

Thank you for reading the question.
It will be really helpful if you could explain what I am doing wrong and what I should be doing.

in Engine by (28 points)

1 Answer

+1 vote
Best answer

functions like _ready() , _process(delta), _physics_process(delta) .. etc are not overridden and parents are initialized first.

by (740 points)
selected by

Oh got it thanks.
Now I changed the ready() in parent to _onready(), and call it from child after initializing.

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.