There is a race condition like follows:
- The PersistentObjectSpawner spawns the PersistentObjects in Awake. --> SavingWrapper is spawned.
- Also in Awake in the SavingWrapper LoadLastScene is called. --> Calls LoadLastScene in the SavingSystem.
- LoadLastScene in SavingSystem calls RestoreState which restores states in SavableEntities.
- One of that saveables is the Experience.cs which in RestoreState calls the event onExperienceGained.
And now the race condition:
- BaseStats is subsribing to that event in Experience, but not before in Start-method!
So at the time the onExperienceGained event is called the first time, nothing has described to that event, which causes an error. That was the reason why for me, in lecture 144 putting LoadLastScene in Awake, didn’t work.