Overriding variable defaults

Godot Version

4.4 Dev 2

Question

How can I override a parent classes default variable? Some Control types for example override the stretch type and other default values of their parent class (the basic Control Node). They are highlighted in yellow in the local documentation.

How can I make my own class which for example inherits from CharacterBody3D and has a default position of vec3(0.0, 1.0, 0.0)?

The character body is just an example, I just wanna know how to override defaults.

1 Like

This is how to make a custom class:

class_name MyClassName
extends ParentClass

#script
#...
#...

I think you can’t override any defaults of a parent class. But I think that is a general thing with object oriented programming. If you want to dive deeper into object oriented programming in godot with abstract, virtual, … classes i advice you to use the .net version with c#. I hope that helps.

I do full agree with this being how inheritance works. But Godot does it themselves as seen here!

The yellow text is german, translated it means [overrides Control: true]
So I feel like when the engine gets to do stuff like this, we should too.

i think this only works with gdextension or @export-variables

1 Like

How is it some through export variables?

you declare an export variable and then you can edit it in the inspector:

@export var value: int = 10