0 votes

I noticed that if I have a gd script, which is then extended by another gd script where both define a _physics_process function, the extending script automatically calls the super version of _physics_process. Based on this GitHub issue, I would expect the super version to be called only when I explicitly call it with ._physics_process(). As this seems to not be the case, I have a few questions about this. Do all functions automatically call their super versions? If not, which functions do call their super versions? Why do they call their super versions? Lastly, is there a way not to call the super version?

asked Aug 21, 2018 in Engine by shianiawhite (100 points)

1 Answer

+1 vote
Best answer

In general, functions are called the way you would expect. However, some functions (such as _process or _physics_process are called by the engine using call_multilevel, which means it will call each method of the class hierarchy.
I am not sure what was the intent behind this, it's as if engine writers wanted to "simplify" the work of the script writers when inheritance is used, but personally I find it confusing because it is basically an exceptional and uncontrolled behavior.

answered Aug 21, 2018 by Zylann (27,004 points)
selected Sep 3, 2018 by shianiawhite

This is pretty close to what I expected. Do you happen to know if there's a list of functions that do this? And also if you can choose not to do this with these functions? I'm guessing you can't choose not to, as the reason these ones do preform this multilevel call is because it's a workaround to make them work, but if you happen to know otherwise, that would be great. Thank you!

After doing a quick search in the source code, I found these methods are called this way:

_notification
_enter_world
_exit_world
_process
_physics_process
_exit_tree
_gui_input

There is also _set, _get and _get_property_list mentionned in the doc: http://docs.godotengine.org/en/3.0/development/cpp/object_class.html?highlight=multilevel#binding-properties-using-set-get-get-property-list

Maybe also _init? Or even all special methods starting with _...

There was a discussion about this system a while ago, then the author closed the issue... even though more people added to the conversation afterwards ^^"
https://github.com/godotengine/godot/issues/6500

the same for _ready

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.