I have a game object that displays text information (some number).
The number is controlled from a script that is attached to that game object.
I’d like the changes to reflect in the editor as i change this number.
So far, i got away using this:
private void OnValidate()
{
UpdateText();
}
Whenever i change a value, the change will be reflected immediately.
There are 2 issues with this approach:
- The OnValidate callback should be used for validating data. This is kind of a hack to use that for updating other things.
- Whenever i load the game object (e.g: from scripting) and not by dragging it into the scene, it will not update its text using OnValidate (since no “change” was done to the data)
Is there any better way to achieve this? I know about [ExecuteInEditMode]
, but this is “dirty” - forcing me to add another component to my game object, one that i don’t need when releasing the game.