Show Export Variable Changes on Object

Godot Version

Godot 4.2

Question

In short, I have an object, a switch, and I would like to create instances of it which default to on and some which default to off. This is simple enough to achieve with an export variable, but I was wondering if there was a way to reflect these changes visually in the editor.

Specifically, I would like these switches to appear toggled upwards or downwards in the editor, depending on if they are default on or off.

I’m worried less about specific implementation here (i.e. helping my specific case) and more about theory. What methods can you go about doing this? For those with more experience, are some ways better than others? More info below the fold.

The Fold

Here, I’m using an AnimationPlayer to handle the position of the switch itself.
The functional but not ideal solution I initially came up with was just to put some code in the _ready function that skips to the end of the animation, and sets variables accordingly. This works, but all switches appear identical within the editor. I read a little bit about the @tool keyword (?) and that seems like the sort of thing I’m looking for, but it seems quite complex and the documentation page has a good number of warnings on it.

If @tool is the way to go, are there any pitfalls or confusing aspects I should avoid / know about?

This seems like a very common question, but I was unable to find any solution, so apologies if this is a repeat of another question.

1 Like

Your only option is running scripts in the editor using the @tool annotation.