Handling of change of field or key type
Posted: Wed Sep 09, 2020 6:13 pm
Status
Requested
Complexity
6/10
Description
Some method of handling previously saved field which has since has it's data type changed without creating an ES3Type.
The most effective way of doing this is likely to be using attributes, similar to Unity's FormerlySerializedAsAttribute.
Note that there currently exists a solution to this: to turn off type checking and ensure that you're providing the precise type of the object as the generic parameter when saving and loading (i.e. not using an inherited class as the generic parameter). The following script demonstrates this:
Requested
Complexity
6/10
Description
Some method of handling previously saved field which has since has it's data type changed without creating an ES3Type.
The most effective way of doing this is likely to be using attributes, similar to Unity's FormerlySerializedAsAttribute.
Note that there currently exists a solution to this: to turn off type checking and ensure that you're providing the precise type of the object as the generic parameter when saving and loading (i.e. not using an inherited class as the generic parameter). The following script demonstrates this:
Code: Select all
using UnityEngine;
public class ChangedTypeTest : MonoBehaviour
{
void Start()
{
ES3Settings.defaultSettings.typeChecking = false;
OriginalClass originalClass = new OriginalClass();
originalClass.myInt = 456;
ES3.Save<OriginalClass>("myKey", originalClass);
RenamedClass renamedClass = ES3.Load<RenamedClass>("myKey");
Debug.Log(renamedClass.myInt);
}
public class OriginalClass
{
public int myInt = 123;
}
public class RenamedClass
{
public int myInt;
}
}