Not loading between levels

I have a problem on loading scenes between levels, when i tried to go from 1 level to other level, the fader just comes in screen forever and doesnt load,

NullReferenceException: Object reference not set to an instance of an object
RPG.SceneManagement.Portal.UpdatePlayer (RPG.SceneManagement.Portal otherPortal) (at Assets/Scripts/SceneManagement/Portal.cs:65)
RPG.SceneManagement.Portal+d__8.MoveNext () (at Assets/Scripts/SceneManagement/Portal.cs:54)
UnityEngine.SetupCoroutine.InvokeMoveNext (System.Collections.IEnumerator enumerator, System.IntPtr returnValueAddress) (at <526469d5a48c43eebd9af19f8745afa1>:0)

Hi Bla_CK,

The fader is stuck because the Portal coroutine encountered a null reference error and stopped progressing, causing the Fader to never receive the FadeIn() message.

The null reference is occurring in the Portal Script in the UpdatePlayer() method.
Either the Player was not located in the new scene (is it tagged with “Player”?) or the Portal couldn’t find a matching portal.
Let’s add a few debugs to figure out which this is:

private void UpdatePlayer(Portal otherPortal)
{
      if(otherPortal==null)
      {
            Debug.Log($"No portal matching {destination} could be found in the scene!");
            return;
       }
       GameObject player = GameObject.FindWithTag("Player");
       if(player==null)
       {
             Debug.Log($"No player was found in the scene!");
             return;
        }
        /// rest of the method
}
1 Like

Thank you so much @Brian_Trotter for solving my problem, I was stuck like 2 weeks and suddenly your code makes everything working,
Hey Brian can u fix this error too;;

Failed to create agent because it is not close enough to the NavMesh
UnityEngine.Behaviour:set_enabled(Boolean)
RPG.Movement.Mover:RestoreState(Object) (at Assets/Scripts/Movement/Mover.cs:68)
RPG.Saving.SaveableEntity:RestoreState(Object) (at Assets/Scripts/Saving/SaveableEntity.cs:39)
RPG.Saving.SavingSystem:RestoreState(Dictionary`2) (at Assets/Scripts/Saving/SavingSystem.cs:85)
RPG.Saving.SavingSystem:Load(String) (at Assets/Scripts/Saving/SavingSystem.cs:35)
RPG.SceneManagement.SavingWrapper:Load() (at Assets/Scripts/SceneManagement/SavingWrapper.cs:34)
RPG.SceneManagement.d__8:MoveNext() (at Assets/Scripts/SceneManagement/Portal.cs:52)
UnityEngine.SetupCoroutine:InvokeMoveNext(IEnumerator, IntPtr)

That one is more of a warning than an error. It’s a momentary bit of confusion on the NavMeshAgent’s part when we move the character during portals. On the very next frame, the NavMeshAgent should get it’s act together and function properly, so it’s not even noticed by the player.

1 Like

ok i got it, thank you so much Brian.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms