Consider the following example :
[Serializable]
public class ClassA : ScriptableObject
{
[SerializeField]
ClassB[] mBs;
}
[Serializable]
public class ClassB
{
[SerializeField]
int mValue;
}
[Serializable]
public class ClassC : ScriptableObject
{
[SerializeField]
ClassB mB1;
ClassB mB2;
void Init ( ClassA lib, int index1, int index2 )
{
mB1 = lib.mBs[ index1 ];
mB2 = lib.mBs[ index2 ];
}
}
ClassA instance is the owner of ClassB instances, like a library.
ClassC instance references ClassB instances, from a ClassA instance.
Doing this at runtime and I have c.mB1 === a.mBs[ index1 ] and so for c.mB2.
But when serializing, then deserializing, it seems that it’s not true anymore.
Actually, serialization makes a copy of ClassB instances and put them on ClassA and ClassC serialized objects.
I don’t wanna make ClassB extend from ScriptableObject because I don’t wanna have to save ClassB instances manually with AssetDatabase.AddObjectToAsset ( eachB, a ), like I do for ClassC instances, whom I want them be directly drag’n’drop-able from the Project Window.
Is there any way to force serialization to keep just a reference on a object ?