[deleted]
- Edited
Plates This Determine Stepped Kitchen Scared About Light Period
Plates This Determine Stepped Kitchen Scared About Light Period
In Godot 4.0, you will need to call super.base_function_here
, but in Godot 3 you need to call .base_function_here
. For better or for worse, GDScript does not automatically call parent functions automatically. C# calls parent functions though, which would give you the desired output.
Rhyme Crop Trace Lamp Unhappy Equal Consider Trip Twelve
I do not know. It should be possible in the C++ code, but I have no idea if the information of whether a function is overriden or not is exposed/passed to GDScript.
Wolf Pattern Guess Death Widely Sing Meat Minute Grade
I'm pretty sure that's not an anti pattern. That's why it's called overriding and not extending.
I think most languages do it that way. If you want to call the base class, just don't override it and it will automatically be called. Otherwise you can call both by calling the super in the override, or just call the override by not calling the super.
Proper pattern for this would be
# Parent class
extends Node
class_name CustomNode
func _print_something():
print("Hello")
_on_print_something()
# The virtual function extending _print_something()
func _on_print_something():
pass
# Child class
extends CustomNode
func _ready():
_print_something()
func _on_print_something():
print("World")
# Output when Child class is _ready
Hello
World
For deeper hierarkies use composition instead, and you save yourself a lot of work by decoupling responsibilites.
What if OP wants to output something before? Proper pattern is:
# Parent class
class_name CustomNode
extends Node
func _print_something()"
_before_print_something()
print("Hello")
_after_print_something()
func _before_print_something():
pass
func _after_print_something():
pass
# Child class
extends CustomNode
func _read():
_print_something()
func _before_print_something():
print("Oh, wow!")
func _after_print_something():
print("World")
Output of child class _ready() would be
Oh, wow!
Hello
World
For deeper hierarchies you might need to add own custom callbacks to child node:
func _before_before_print_something():
pass
func _after_before_print_something():
pass
func _before_after_print_something():
pass
func _after_after_print_something():
pass
Doing more than two levels of hierarchy is problematic and thus not recommended.