When restoring from a saved state, I am getting exceptions the RestoreState() for classes where I’ve implemented the LazyValue. It seems that RestoreState() is occurring before Awake, but I’m not sure how that can be.
For instance, in Health.cs… the exception will show _health to be null in the following snippet. And this is resolved by setting _health to a new LazyValue, but that seems to defeat the purpose of this lesson.
public void RestoreState(object state)
{
_health.value = (float)state;
// Check for death
if (_health.value <= Mathf.Epsilon)
{
Die();
}
}
Here is the Heatlh.Awake()…
private LazyValue<float> _health;
private Animator _animator;
private GameObject _instigator;
public State HealthState { get; set; }
public float HealthPoints
{
get { return _health.value; }
}
private void Awake()
{
_animator = GetComponent<Animator>();
_health = new LazyValue<float>(InitializeHealth);
}
Thanks!