Hi,
So I’m trying to get default values to work when creating an array of serializable class.
The serializable class looks like this:
[System.Serializable]
public class WaveDefinition
{
public float WaveLength = 5.0f;
}
and the other class where I create the array looks like this:
public class PopulateArray : MonoBehaviour
{
[SerializeField]
private WaveDefinition[] _Waves;
}
in this case the default value for the first element is always 0.
If I modify this value and add another element the default value of the new element will be the same as the previous element.
I tried using ISerializationCallbackReceiver to initialize the values like so:
[System.Serializable]
public class WaveDefinition : ISerializationCallbackReceiver
{
public float WaveLength = 5.0f;
private bool _Deserialized = false;
public void OnBeforeSerialize()
{
}
public void OnAfterDeserialize()
{
if (_Deserialized)
{
return;
}
this.WaveLength = 5.0f;
this._Deserialized = true;
}
}
while this works to set the default values, when I add an other element all of the elements will be reset to the default values.
Can someone help me figure this out?
Thanks!