Skip to content

Instantly share code, notes, and snippets.

@lucasmeijer
Created September 30, 2013 18:38
Show Gist options
  • Save lucasmeijer/6768143 to your computer and use it in GitHub Desktop.
Save lucasmeijer/6768143 to your computer and use it in GitHub Desktop.
[DataVersion(2)]
public MyClass : MonoBehaviour
{
public float m_myFloatThatUsedToBeAnInt;
}
#if UNITY_EDITOR
static class DataUpdater
{
[DataUpdaterFor(typeof(MyClass))]
static void DeserializeOldData(SerializedObject oldData, SerializedObject newData)
{
//oldData is the old serialized data
//newData will be populated by Unity with a "best guess" (similar to what unity does today)
//it's up to you to set newData serialized data to be how you want it
//this method would be called when the typetree between stored data and new class is different.
//(i.e. you added or changed a field), or when the DataVersion is different between the stored data
//and the current code
//Questions: do you think it's good enough to have this API only work on MonoBehaviour/ScriptableObject,
//and not on arbitrary nested classes. (you could update those too, but the code for that has to be in the consuming
//monobehaviour, and not in the custom class itself)
}
}
#endif
@darktable
Copy link

How common of a problem is this? The few times I've needed to migrate data between types in Unity, I did it by directly monkeying with the YAML serialized data (of a .prefab or .scene). You could provide a YAML munging library and let people go nuts with it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment