Scene Loading not working

I’m having some issues since completing the “Resetting the Default Animator” to “Pickup Respawning”

my scene fades to black but that’s as far as it goes

I get one warning which is

DontDestroyOnLoad only works for root GameObjects or components on root GameObjects.
UnityEngine.StackTraceUtility:ExtractStackTrace ()
RPG.SceneManagment.Portal/d__8:MoveNext () (at Assets/Script/SceneManagment/Portal.cs:40)
UnityEngine.MonoBehaviour:StartCoroutine (System.Collections.IEnumerator)
RPG.SceneManagment.Portal:OnTriggerEnter (UnityEngine.Collider) (at Assets/Script/SceneManagment/Portal.cs:27)

I have looked through other topics like moving stuff to Awake () instead of Start () but I’ve had no luck

When we transition from one scene to another, we temporarily mark the source portal as DontDestroyOnLoad. This physically takes it out of one scene and moves it into a scene that is always loaded.
If the portal is a child of another GameObject (say a GO named Portals that holds all the portals in the scene, or in the environment GO) Unity can’t extract the portal and move it to the DontDestroyOnLoad scene (since it has a parent).
Move any portals you have to the root of the heirarchy and this will go away.
This is one area where I believe Unity should thrown an explicit error instead of a warning, because it’s easily missed.

Hi Brian

Thank you I believe that helped, I then got the below

NullReferenceException: Object reference not set to an instance of an object
RPG.Combat.Fighter.CaptureState () (at Assets/Script/Combat/Fighter.cs:133)
RPG.Saving.SaveableEntity.CaptureState () (at Assets/Script/Saving/SaveableEntity.cs:26)
RPG.Saving.SavingSystem.CaptureState (System.Collections.Generic.Dictionary`2[TKey,TValue] state) (at Assets/Script/Saving/SavingSystem.cs:72)
RPG.Saving.SavingSystem.Save (System.String saveFile) (at Assets/Script/Saving/SavingSystem.cs:29)
RPG.SceneManagment.SavingWrapper.Save () (at Assets/Script/SceneManagment/SavingWrapper.cs:37)
RPG.SceneManagment.Portal+d__8.MoveNext () (at Assets/Script/SceneManagment/Portal.cs:56)
UnityEngine.SetupCoroutine.InvokeMoveNext (System.Collections.IEnumerator enumerator, System.IntPtr returnValueAddress) (at <88f69663e9a64d00b2091dd8dfd4d38f>:0)

After rewatching some lectures and doublechecking the code I put the below in Awake() and that has resolved the issues now

if (currentWeapon == null)
{
EquipWeapon(defaultWeapon);
}

last error I’m getting after those fixes is related to the NavMesh, I’ll trace my steps back again to see if I missed something out

Failed to create agent because it is not close enough to the NavMesh
UnityEngine.StackTraceUtility:ExtractStackTrace ()
RPG.Movement.Mover:RestoreState (object) (at Assets/Script/Movement/Mover.cs:68)
RPG.Saving.SaveableEntity:RestoreState (object) (at Assets/Script/Saving/SaveableEntity.cs:39)
RPG.Saving.SavingSystem:RestoreState (System.Collections.Generic.Dictionary`2<string, object>) (at Assets/Script/Saving/SavingSystem.cs:85)
RPG.Saving.SavingSystem:Load (string) (at Assets/Script/Saving/SavingSystem.cs:35)
RPG.SceneManagment.SavingWrapper:Load () (at Assets/Script/SceneManagment/SavingWrapper.cs:42)
RPG.SceneManagment.Portal/d__8:MoveNext () (at Assets/Script/SceneManagment/Portal.cs:51)
UnityEngine.SetupCoroutine:InvokeMoveNext (System.Collections.IEnumerator,intptr)

You can safely ignore the NavMesh “error”. It’s more of a warning that generally clears itself on the next frame.

1 Like

Awesome, thank you for the help Brian, I appreciate it :slight_smile:

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

Privacy & Terms