Can you reflect the setting of an export variable in the editor?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By alwaysusa

Unreal has a function called “construct” (or something similar, been a while) where the setting of a public variable (export in Godot) will update the object in the editor viewport. Effectively, it’s a script that runs while the object is being edited, so you can add variables or logic that will show before you run the game. Is this possible in Godot?

Example:

I add an export variable called “is_red”. If true, the sprite turns red. When I run the game, the change will show, but is there a way to show that change in the editor when I select the variable in the inspector?

Cheers!

:bust_in_silhouette: Reply From: Zylann

The closest functionality allowing to do this would be the tool keyword.
Write it at the top of your script, and it will make the script run in the editor, just like it does in game.
See Running code in the editor — Godot Engine (stable) documentation in English

That’s perfect! Thank you. Very helpful.

alwaysusa | 2020-03-24 20:50