Whenever I rename a public variable, I lose all values/references of that variable in all objects with that component.
What’s the unity way to rename public variables? I guess it’s not with the IDE (unless monodevelop doesn’t have this problem, I’m using visual studio).
2 Likes
I found a solution that’s still quite tedious for simply renaming a variable but for as often as one needs to rename a variable it’s worth it and works perfectly.
I found the attribute [FormerlySerializedAs(“yourVariablesPreviousName”)] in the UnityEngine.Serialization namespace.
-
Place the attribute before the variable you wish to rename.
-
Rename the variable and save changes.
-
Switch to the inspector, wait for the name to change, it will have reserialized with the new name and keep all values and references.
-
Remove the attribute (probably optional).
1 Like