Refactoring and Renaming
Sometimes during development programmers need to rename script properties or fields, change asset data format or refactor code. As this is pretty common case for longer projects please follow this documentation page to learn how to handle those kind of situations with an ease. Good luck!
Renaming property or field
In this example, script had field named
PlayerSpeed that was renamed to
Speed. By adding
JsonProperty attribute to C# filed you cna redirect serializer to use other name. It works in the same way for game scripts and json asset objects.
// C# // Before: public float PlayerSpeed; // After: [JsonProperty("PlayerSpeed")] public float Speed;
Moving fields or properties when refactoring code
In this example, asset had field named
WalkableRadius but it was removed and refactored into structure
SurfaceOptions. By adding property you can use its setter method to perform data upgrade on deserialization. Make it
Serialize attribute so it will be using serialization and mark as
Obsolete so it won't be saved anymore.