Hello,
I was having an issue where at first when I went through a portal and it faded out, I would get a null reference regarding my warp to location when restoring the player’s location. After testing I found that it was because the navMeshAgent was null, it wasn’t loading in before the saving system tried to move the player. After a simple if statement making sure that the navmesh was present before warping the player I thought I was clear. Next when we made Start load the scene to the saved scene, I had an issue where previously dead enemies were still standing, their health was 0 but the die animation wasnt triggering. Again testing found that the animator loads but there is a timing conflict with restore state.
In the end my solution was to go into SavingSystem.cs and under LoastLastScene I added a WaitForSeconds after the LoadSceneAsync and before RestoreState. Not sure how long lasting this fix is, and there is a half second jarring when the application loads but it works.
public IEnumerator LoadLastScene(string saveFile)
{
Dictionary<string, object> state = LoadFile(saveFile);
int buildIndex = SceneManager.GetActiveScene().buildIndex;
if (state.ContainsKey("lastSceneBuildIndex"))
{
buildIndex = (int)state["lastSceneBuildIndex"];
}
yield return SceneManager.LoadSceneAsync(buildIndex);
yield return new WaitForSeconds(0.5f); //added myself
RestoreState(state);
}