Closed
Description
Godot version
3.3.3.stable, 4.0.dev (c97afc0)
System information
N/A
Issue description
Object::notification()
always calls _notification()
in order:
- For built-in classes - possibly in reversed order according to
p_reversed
parameter. - For scripts - always in the same order.
- For extensions (4.0 only) - always in the same order.
Relevant source code:
Lines 840 to 850 in c97afc0
So for example for an object b
of type B
with inheritance:
Object
< Node
< A
(gdscript) < B
(gdscript)
here's a comparison of the current behavior and what I'd say is expected behavior:
call | current call order | expected call order |
---|---|---|
b.notification(12345, false) |
1. Object::_notification 2. Node::_notification 3. B::_notification 4. A::_notification |
1. Object::_notification 2. Node::_notification 3. A::_notification 4. B::_notification |
b.notification(12345, true) |
1. Node::_notification 2. Object::_notification 3. B::_notification 4. A::_notification |
1. B::_notification 2. A::_notification 3. Node::_notification 4. Object::_notification |
Also current notification()
's description in the docs is misleading because reversed
parameter currently doesn't affect the order of execution of in-script _notification()
overrides.
Steps to reproduce
Run such script:
tool
extends EditorScript
func _run() -> void:
var b := B.new()
for reversed in [ false, true ]:
print("reversed = %s" % [ reversed ])
b.notification(12345, reversed)
class A:
func _notification(what: int) -> void:
if what == 12345:
print("A")
class B extends A:
func _notification(what: int) -> void:
if what == 12345:
print("B")
Output:
reversed = False
B
A
reversed = True
B
A
Minimal reproduction project
Just run script above.