- Home /
How to set a public variable back to it's original value?
Hey there! I think this is a very simple question, but if I would know the answer it would save a little bit of time.
I want to switch back to the original value of a public variable, after I changed it's value by another function. So is there a simple way to tell the variable to recover it's original value that I had entered via interface?
I think you will need another wariable to save the previous Value.
Answer by tanoshimi · Jun 19, 2014 at 10:32 AM
No, variables do not "remember" previous values once they are changed. You'd need to record that initial value in another variable (or, perhaps preferably, in a const)
Clearly, Unity does know the starting value of all public variables, and it does know how to restore a variable to it's Inspector value. But currently only does it automatically at start, and for all variables at once.
Is there a way to ask Unity to rerun the "public variable setter," and to specific only one variable? I'd guess no. It's rare enough, and easier to do other ways. Like the other variable trick, or reading it from the prefab.
Your answer