Running the ready function of parent and child nodes

Godot Version

4.2.1

Question

So I have a class I named Entity.

I then have another class called human_enemy that inherits from entity.

When I spawn a node of the human_enemy I would like it run both ready functions so that I don’t have to copy the code over from the parent node. Right now, if I remove the last row in the human enemy ready function it just spawns in with 0 health. This is obviously a minor change right now but as I progress it would mean copying more and more code over. Is there a straightforward way to do so or do I have to find a workaround?

1 Like

If I understood correctly you want to call the ready function of the inherited calss? This is what the “super” keyword is for.

That’s a typical object oriented topic. Here is an example for GDscript but I’m sure there is a similar thing for C# GDScript reference — Godot Engine (stable) documentation in English

1 Like

I’m not sure why I didn’t look this up before but you response made delve into it. Super is only for GDScript but an equivalent for C# is base._Ready() which calls on the ready function of the parent class.

Thank you very much.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.