How to override native function?
Asked Answered
S

3

0

So I want to Override a build-in function to adjust it to my needs, but I can't get it to work or find any solutions, the Override just doesn't get called.
Details:
I want to extend the select() method of an OptionButton to emit a signal every time an item is selected. I'm just assuming that this is the method that is always called when ANY changes happen to the selected item by ANY sources, for example when there isn't an item added initially (selected = -1), but when I add an item, it is selected automatically (selected = 0). In these kind of scenarios I want that custom signal to be emitted too. Is there any other way to make this work besides my idea if that does not work?
Thanks!

Sosthenna answered 10/8, 2023 at 15:41 Comment(0)
T
0

The select function isn't virtual as you can see from the source: https://github.com/godotengine/godot/blob/master/scene/gui/option_button.h#L122

I assume that means it can't be overriden.

Furthermore the code indicates that this assumption

I'm just assuming that this is the method that is always called when ANY changes happen to the selected item by ANY sources

is wrong.

Thessalonians answered 10/8, 2023 at 15:59 Comment(0)
F
0

Can be your solution using an Auto-load script? Not sure about that override but with autoload you can store variable and functions that works and can be manipulate in any part of your game.

Frei answered 10/8, 2023 at 16:0 Comment(0)
S
0

Thessalonians Hmmm okay, thanks for the information! Gonna have to find a workaround then

Sosthenna answered 10/8, 2023 at 16:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.