|Topic was automatically imported from the old Question2Answer platform.
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?
In general, functions are called the way you would expect. However, some functions (such as
_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.
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!
shianiawhite | 2018-08-21 19:44
the same for
chiara_jm | 2020-04-05 21:05
In the Github thread, reduz commented on Sep 15, 2016:
callbacks get called at all levels, back when we had Squirrel
programmers used to forget calling the parent functions all the time
for callbacks they handled different and it was kind of a mess.
I’ve worked with an in-house game engine written in C++, and for some functions, forgetting to call the base implementation resulted in very bad behavior. Maybe the Godot engine devs made this design choice simply to avoid such situations?
placroix74 | 2022-10-13 02:13