_ready call order is reversed from typical inheritance

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

When inheriting, typically the child is called first and it has control over when to call the parent function. _ready is implicitly called, and it is first called on the parent, then the child. This makes it difficult to override or initialize in the child node.

I suppose you could create and call an init function in the parent at the beginning of _ready, but this seems messy. The order is reversed from usual and a small amount of boilerplate is required. Is this the preferred approach, or is this a bug?

:bust_in_silhouette: Reply From: coffeeDragon

I’m not sure what exactly you mean.
But the _ready function isn’t there for initialization but for the gui rendering engine. Where it makes sense to first render the root object and then everything else.

For initialization just override _init(args) and call it alla myNode.new(args)
There it works like you would expect and you can acutally use paramteres.
see: Object — Godot Engine (3.0) documentation in English

:bust_in_silhouette: Reply From: hilfazer

It’s an intended behaviour, at least for now, so you’ll need that workaround.

It seems to be generally disliked and it’s going to be changed for C#:

that behaviour affects all engine callbacks (like input and process), it is not ideal in particular in _process when one may want to work on some variables before processing with the base class logic.

The workaround is to not use the engine callbacks in base classes, use another method you can call in derived ones.

eons | 2018-02-16 23:04