Fader bug [Solved]

I have a weird error where I get an error message posted on the bottom of this post. This happens just at the fader.FadeIn call in Portal.cs. It only happens when transitioning from scene 1 to scene 0, but it works as intended the other way around. This in return does not let the code reach the destroy of the portal of scene 1, so I keep getting portals in scene 0 every time I come from scene 1. If I check that fader exists and then if it doesn’t I don’t call FadeIn, then the portal gets destroyed as intended, but of course I don’t get the fade in.

The reason that the title is [partially solved] is that, if I remove PersistentObjects from scene 1 and then start the game from scene 0 it all works as intended. However, then the problem is that if I start the game from scene 1 I get the reverse problem with the FadeIn error on scene 1 instead. It seems like the only way it works correctly is if I have PersistentObjects in the scene I start the game from, bot not have it in any other scene. Does anyone have an idea why this weird behavior happens and generally should I have the PersistensObjects on only the starting scene?

"MissingReferenceException: The object of type ‘CanvasGroup’ has been destroyed but you are still trying to access it.
Your script should either check if it is null or you should not destroy the object.
RPG.SceneManagement.Fader+d__3.MoveNext () (at Assets/Scripts/SceneManagement/Fader.cs:28)
UnityEngine.SetupCoroutine.InvokeMoveNext (System.Collections.IEnumerator enumerator, System.IntPtr returnValueAddress) (at <685c48cf8f0b48abb797275c046dda6a>:0)
"

Update: It seems to work correctly when I remove the PersistentObjects from all scenes and let the scrypt in Core spawn it.

Which is exactly as it’s intended to function. If it’s in the scene file already, then the FindObjectOfType will always find the one in the scene and not the one that was spawned in as DontDestroyOnLoad. This makes it imperative that the PeristentObjectSpawner not be in the scene file, only spawned in by the Core.

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

Privacy & Terms