Sitemap
Sean Duggan

Sean Duggan

Fantacode Demo — Fixing Loading

3 min read1 day ago

Alright, so somewhere in the process of things, I wound up with a persistent error when loading scenes.

Scene load failed with status: None, Exception:

UnityEngine.Debug:LogError (object)

SceneChangeManager/<LoadScene>d__22:MoveNext () (at Assets/Scripts/SceneChangeManager.cs:206)

UnityEngine.SetupCoroutine:InvokeMoveNext (System.Collections.IEnumerator,intptr)

This is happening when we try to activate the scene using the existing handle.

AsyncOperation activateOp = handle.Result.ActivateAsync();

It’s indicating that the status is None instead of Succeeded. This is actually probably to be expected. I ran the LoadSceneAsync call with activateOnLoad set to false so that I can let the user decide when to start, so the scene indeed would not have successfully loaded. I need to change my code to check for failure, not for success.

if (handle.Status == AsyncOperationStatus.Failed)
{
Debug.LogError($"Scene load failed with status: {handle.Status}, Exception: {handle.OperationException}");
loadingCanvas.SetActive(false);
yield break;
} else
{
// We should prompt for the user to load. For now, we're going to add a dely.
yield return new WaitForSeconds(2f);

// Activate the scene using Addressables' internal activation logic via Result
AsyncOperation activateOp = handle.Result.ActivateAsync();
while (!activateOp.isDone)
{
yield return null;
}
}

Get Sean Duggan’s stories in your inbox

Join Medium for free to get updates from this writer.

That works! Next step is to actually prompt the user to acknowledge it, if for no other reason than that we have a scene or two that dumps you right into the action.

Press Any Key to Continue

So, simple solution, we’ll create alternate text for the scene having loaded and swap them out.

And then, depending on the input system being used (I’m actually only using Input System, but I like to maintain flexibility), we check for the “any key” in two different ways.

            loadingObject.SetActive(false);
loadedObject.SetActive(true);

#if ENABLE_INPUT_SYSTEM
anyButtonPressed = false;
while (!anyButtonPressed)
{
yield return null;
}
#else
while (!Input.anyKeyDown)
{
yield return null;
}
#endif

For the Input System, that boolean is set by a function set up in our Start method.

InputSystem.onAnyButtonPress.Call(ctrl => { anyButtonPressed = true; });

Hmm… still a long pause before we actually show the UI. That may change when I’m not in the Editor. One other thing I need to fix is that currently, you can click on a scene button multiple times before it finished processing things… I really need to lock that down.

--

--