Hi I got the health state to save and restore before following along with Sam but even after looking at his code in the git I don’t understand why he didn’t have the following bugs I had unless they weren’t tested for.
Which is that the enemies in my game kept chasing me after dying or if they had a patrol root they would float towards the next path they were set to follow.
This also happened after loading including the patrol root if they the player wasn’t nearby to them.
This is my health restore code:
public void RestoreState(object state)
{
_health = (float)state;
if (_health <= 0)
{
PutInDeadState();
}
}
private void PutInDeadState()
{
GetComponent<Animator>().SetTrigger("Die");
GetComponent<ActionScheduler>().CancelCurrentAction();
_isDead = true;
}
To fix this I had to add additional bool checks, the first being in the fighters update adding the additional isdead check:
if (_targetHealth == null || _targetHealth.IsDead || GetComponent<Health>().IsDead) return;
Then in ai controllers PatrolBehaviour:
if (_patrolPath != null && GetComponent<Health>().IsDead == false)
This mostly fixed it except any enemies with a patrol path upon loading would move a few inches towards the next path before stopping.
Sam hasn’t got any of these additional checks so I don’t understand why he doesn’t have these bugs and why the enemy still slightly floats towards the next path upon reload.