0 votes

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?

asked Feb 15, 2018 in Engine by jarlowrey (611 points)

2 Answers

+1 vote
Best answer

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#:

answered Feb 16, 2018 by hilfazer (2,154 points)
selected Feb 16, 2018 by jarlowrey

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.

+2 votes

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: http://docs.godotengine.org/en/3.0/classes/class_object.html#class-object-init

answered Feb 16, 2018 by coffeeDragon (252 points)
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 How to use this Q&A? before posting your first questions.