After a bit of debugging, I discovered that all of the Grunts were starting with their health at Zero…
The reason for this is that Progression, there are actually two entries for Health under Grunt…
That still leaves your characters getting back up after dying, saving, and restarting…
The cause of that is that RestoreState is called before Start()… so there is a trick for this (in a later lecture, we’ll introduce the LazyValue which will make it so you won’t need this trick…
Set healthPoints to -1 (You’ll actually have to do this both in the code and in the inspector because for most of these the healthPoints is serialized.
Now in start, check to see if the healthPoints are -1… if it is, then get the healthPoints from BaseStats. This is a sort of Lazy Evaluation trap (not quite true Lazy evaluation). It just says “Oh, nothing has initialized Health, so I should do it now”. If RestoreState loads, it will have the correct value and then in start it will say “Oh, I don’t need to go to BaseStats”…
That leaves the final issue, the death…
You’re absolutely right, all of the characters with overrides fail to “die” when they’re clearly dead after a
RestoreState… It looks like the issue is a race condition with Animator…
Ordinarily, the Animator should be all set with it’s Override controller in place by the time RestoreState happens. Even when we’re changing the controller with Fighter, it should still work. This is the first time I’ve worked with 2020.1.8, and I’m questioning if there may have been a change in order of operations…
So here was my solution, though it’s a bandage, not a cure…
In RestoreState(), replace Die()
with Invoke(nameof(Die), .01f);