Hi everything related to the portals and scene transition has been working fine for me and at the time of writing this, I have been working through the saving section.
Now suddenly I’m experiencing a very strange null reference exception which is making no sense to me because I can’t identify what is causing this in the code or in any of the object settings.
So I tried deleting the core Gameobject and replaced the prefab and then everything works fine. However whenever I quit the project(close unity completely) and then relaunch and go back into playmode I get the following error again:
NullReferenceException: Object reference not set to an instance of an object
RPG.SceneManagement.Portal+<Transition>d__10.MoveNext () (at Assets/Scripts/SceneManagement/Portal.cs:52)
UnityEngine.SetupCoroutine.InvokeMoveNext (System.Collections.IEnumerator enumerator, System.IntPtr returnValueAddress) (at <823fb226a3f9439cb41fdcb61f9c86a1>:0)
UnityEngine.MonoBehaviour:StartCoroutine(IEnumerator)
RPG.SceneManagement.Portal:OnTriggerEnter(Collider) (at Assets/Scripts/SceneManagement/Portal.cs:36)
The first line it mentions in the error log on line 52:
IEnumerator Transition()
{
if (_sceneToLoad < 0)
{
Debug.LogError("Scene to load not set");
yield break;
}
SavingWrapper savingWrapper = FindObjectOfType<SavingWrapper>();
Object.DontDestroyOnLoad(gameObject);
savingWrapper.Save();
yield return _fader.FadeOut(_fadeOutTime);
yield return SceneManager.LoadSceneAsync(_sceneToLoad);
savingWrapper.Load();
Portal otherPortal = GetOtherPortal();
UpdatePlayer(otherPortal);
yield return new WaitForSeconds(_fadeWaitTime);
yield return _fader.FadeIn(_fadeInTime);
Destroy(gameObject);
}
The specific line is:
yield return _fader.FadeOut(_fadeOutTime);
The next again in portal for line 36 is the startcoroutine call in:
private void OnTriggerEnter(Collider other)
{
if (other.tag == "Player")
{
StartCoroutine(Transition());
}
}
Again this is very odd because it was working fine previously and it works after deleting and replacing the core prefab and then going into play mode, but then the error occurs when relaunching the entire project.
I’m using unity 2021.3.1 LTS if that’s related.