Godot: GDScript bug ? override function _process() still call parent function

Created on 25 Oct 2018  路  5Comments  路  Source: godotengine/godot

Godot version: 3.06 and 3.1 too

OS/device including version: ubuntu 16 64 bit

Issue description: override function still call parent function, but the problem only happened if the child class attached to some object in scene.
i expect only child function _process(): called not with parent _process(): too

the log i expected
child
child
child
child
.....

the log found
parent
child
parent
child
.....

Steps to reproduce:
i will including the test project

Minimal reproduction project:
bug_test.zip

archived documentation enhancement core

Most helpful comment

Known issue, but I can't find the one where it was discussed...
Basically, some special functions like _process are called with call_multilevel, which calls all versions of the function through its inheritance hierarchy... which is by design, and could make sense for _init (constructor), but otherwise I find it confusing (adds invisible exception to what you expect with OOP) and takes control away.

Related Q&A threads:
https://godotengine.org/qa/32105/_physics_process-super-call-occurs-automatically?show=32141#c32141
https://godotengine.org/qa/9244/can-override-the-_ready-and-_process-functions-child-classes?show=9252#a9252

Closed issue: #6500
That one has relevant comments after it was closed, not sure why it was never reopened

All 5 comments

Known issue, but I can't find the one where it was discussed...
Basically, some special functions like _process are called with call_multilevel, which calls all versions of the function through its inheritance hierarchy... which is by design, and could make sense for _init (constructor), but otherwise I find it confusing (adds invisible exception to what you expect with OOP) and takes control away.

Related Q&A threads:
https://godotengine.org/qa/32105/_physics_process-super-call-occurs-automatically?show=32141#c32141
https://godotengine.org/qa/9244/can-override-the-_ready-and-_process-functions-child-classes?show=9252#a9252

Closed issue: #6500
That one has relevant comments after it was closed, not sure why it was never reopened

This caught me out in my current project because it is inconsistent (and undocumented?) behaviour compared to the behaviour of manually created and overridden functions. I feel like it's definitely something that should be reopened (or at the very least warned about in the editor or in some prominent documentation).

It was a bad strategic decisions for default functions. It is against override mechanism. It forces hacking. I had to introduce ignore boolean flags and condition checks to _input(event) methods in super classes.

Godot is getting mature. GDScript should do the same.
Thinking about backward compatibility: What about a compiler/editor settings that could change that to industry standard behavior? The release note could clarify this so old project could work too.

From docs:
"Remember that default functions like _init, and most notifications such as _enter_tree, _exit_tree, _process, _physics_process, etc. are called in all base classes automatically. So there is only a need to call the function explicitly when overloading them in some way."

From Reduz:
"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. "

well it looks like this is not a bug we can close this. my bad not read full manual and just assume based on my experience from other language. but still i think this manual need to put in some special section in manual about OOP in godot if you from another language. let say "migrating from c++ to gdscript".

Was this page helpful?
0 / 5 - 0 ratings