So after I refactored everything (compared my files with the github commits etc etc) as per Sam’s instructions I ran into an error when going from one scene to the next and back again. Upon re-entering the Scene I originally spawned in I get:
NullReferenceException: Object reference not set to an instance of an object
Scripts.Movement.Mover.RestoreState (System.Object state) (at Assets/Scripts/Movement/Mover.cs:74)
Which refers to:
public void RestoreState(object state)
{
var serializableVector3 = (SerializableVector3)state;
_myNavMeshAgent.Warp(serializableVector3.ToVector3()); // This line
_actionScheduler.CancelCurrentAction();
}
I tried disabling Navmeshagent instead and using player.transform but the result is the same.
If I swap places of the Navmesh line and the ActionSched. line the error occurs on the ActionSched. line so it is clearly behaving as if we do not have an Object attached to the component.
If I shuffle around where I call Load() in my Portal.cs I can get it to work (kind of):
IEnumerator Transition()
{
DontDestroyOnLoad(gameObject);
Fader fader = FindObjectOfType<Fader>();
SavingWrapper wrapper = FindObjectOfType<SavingWrapper>();
yield return fader.FadeOut(fadeOutTime);
wrapper.Save();
yield return SceneManager.LoadSceneAsync(sceneToLoad);
wrapper.Load(); // Doesn't work here
Portal otherPortal = GetOtherPortal();
UpdatePlayer(otherPortal);
// Doesn't work here either.
yield return new WaitForSecondsRealtime(loadSceneTime);
// Works here (well as it, it does not give me the same error, it still bugs out due to the fading glitching out etc)
yield return fader.FadeIn(fadeInTime);
// Works here (but the player starts teleporting back and forth, obviously not a great place to have it, but again, I am not getting the error)
Destroy(gameObject);
}
So, to me, it certainly seems like it is saying something like “Hey the Guid referred to an Object that no longer has this particular Mover.cs component from within which you are trying to do stuff”. Does this have to do with the fact that we carry two different GUID’s for our Player Object in our two scenes so that when we go back and forth it is trying to access the component of the Object that is no longer loaded? But if so, why does it work when i change scene the first time but not the second time?
My brain hurts…
(it was all working as expected before we refactored most of it into Mover.cs)
Help, please…