Using a custom button state from a theme

Godot Version

4.2.1

Question

Hi! I’m looking to do something very simple, yet I have lost two days over it already.

I have a button. I create a theme. I add the “Button” node in my theme to edit its properties. I go to the StyleBoxFlat tab. There, I see different states for my button: hover, normal, disabled, etc.

I also have the possibility to add a custom state.
My question is as follow: how the hell do I access this custom state through code later on? I have tried literally everything and I cannot find a straight answer anywhere, to the point it’s driving me crazy. Let’s say my state is “locked”.

If the button.disabled is true, it loads the “disabled” version of the theme.
How do I do the same for button.locked = true??

Thanks in advance.

You can add extra properties to the theme but that does not mean that the node will magically know how to use them. You’ll need to code your own button from scratch if you want to go that route. Here’s the Button draw code godot/scene/gui/button.cpp at 9c7e4031c03edb1f40c9a2876f6876fb2d404141 · godotengine/godot · GitHub

It’s better if you use a theme type variation and set it when button.locked is true and remove it when is false.

Yeah, I thought it would be way simpler than that… Ultimately the theme type variation does the job perfectly. Thanks a lot for your help!