When extending the parents _ready function is called even after overriding?

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

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

parent:

extends KinematicBody2D
class_name Enemy
func _ready():
    print("parent")
    LoadRaycasts()

child:

extends Enemy
func _ready():
    print("child")
    health=20
    speed=30
   .ready()

I was expecting the output as:
child
parent

But what I get is:
parent
child
parent

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

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
parent:[KinematicBody2D:1185]
child:[KinematicBody2D:1185]
parent:[KinematicBody2D:1185]

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.

:bust_in_silhouette: Reply From: supper_raptor

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

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

_nabajit | 2020-05-29 17:26