Process and Update Method of Overwritten GDExtension classes

I am writing a addon using GDExtension. I ran into the following problem.
In my C++ class I overwrite the _ready and _process methods to connect the node to all necessary signals, set things up etc.
I want the users to be able to inherit the classes I write to implement more custom behaviour. Though if they overwrite the process or ready method and don’t call the base methods, the script won’t work or even throw errors, because some variables might not be initialized yet.
How can I make sure that the C++ implementations get called?

I also ran into this problem earlier, I have found a way to get around it but am not 100% convinced that this is the correct way.

By binding the virtual methods with the actual name, the Editor complains that the original _enter_tree() is overriden.

To get around this problem, I bind the virtual methods without the underscore prefix and called them in the relative virtual methods.

void Extension::_bind_methods() {
	ClassDB::bind_method(D_METHOD("enter_tree"), &Extension::_enter_tree);
	ClassDB::bind_method(D_METHOD("ready"), &Extension::_ready);
func _enter_tree():

func _ready():

This worked for me, hope it helps.

If the overwriting gdscript instance didn’t call the super method, the C++ method still wouldn’t be called, right?

That is what I am experiencing. Otherwise, if the C++'s virtual methods are not overriden in gdscript, they would still run.

How to the build in Nodes work? They do stuff every frame and the ready and process methods still get called.

Plenty of classes use notifications. They’re called regardless of whether or not they’re overwritten in scripts.

The godot-cpp test has an implementation.

Thank you so much!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.