- Home /
Starting Play mode resets values for serialized class in the Inspector
Hi, I'm relatively new to Unity.
I'm playing with writing custom player controller based on the standard one. For some reason I faced strange behaviour. I have [Serializable] class CurveControlledBob which contains [SerializeField]. Then I have MonoBehaviour class which has CurveControlledBob variable. Every time I enter Play mode values in the Inspector – just for this serialized class – reset to declaration values. They return to changed values after leaving Play mode.
[Serializable]
public class CurveControlledBob
{
[SerializeField] private float baseInterval = 1.0f;
// Some other code
}
public class MyMonoBehaviour : MonoBehaviour
{
[SerializeField] private CurveControlledBob headBob = new CurveControlledBob ();
// Some other code
}
If I change [SerializeField] private float baseInterval to public float baseInterval then nothing happens. This value still resets on Play. If I remove = 1.0f then it will always be 0f in Play mode. So it seems like this class just can't get values from the Inspector. I know that people have similar issues when using custom editor inspectors. But in this case I didn't write any of them, it's just regular one.
I hope that I'm just stupid and missed something here.