how can I rename a field in a Unity script, but keep it's assignment in the Unity Editor inspector? Say I have

public int x;

I assign "1" to x in the inspctor and then i rename x to y in the script. The assignment will then be lost. Is there a way to keep it?

I'm using Visual Studio.

Question author Tavados | Source



Doing the following will save the value in the inspector. It can be removed after the scene has been saved again.

[FormerlySerializedAs("x")]public int y;

Read more about it here and here

Answer author Fredrik

Ask about this question here!