Upgradable Data
Unity's prefab system allows you to override specific properties on a prefab instance. This lets you customize the prefab.
However, if properties are removed or renamed, these overrides will be lost.
It's also a bit of a pain to rename or remove variables in general. Unity's FormerlySerializedAs
attribute allows you to keep the serialized data, but these have to be kept around forever, since it's always possible that someone's old prefab will still have that old data on it.
The Core package provides a solution to this in the form of upgradable data. Data starts at version 1. Each version can upgrade itself to the next version (except for the last version, which does nothing when upgraded).
This is a one-way process. Data cannot be downgraded.
Additionally, overrides can be added to modify the original upgradable data. Overrides are upgradable data in their own right.
Suppose you have the following scenario:
- A prefab has a component that contains
DataV1
- You've attached an override for
DataV2
- The latest version of the data is
DataV3
When code wants to work with the component's data, these things will happen:
- The code upgrades the override – which is for
DataV2
– to one forDataV3
- The code asks the override to produce a
DataV3
- The override upgrades the original data – which is a
DataV1
– toDataV3
- The override produces a new
DataV3
As long as the upgrade process doesn't produce invalid data, you can transparently use any old data!