#Scene gets stuck at 0% loaded and refuses to progress when loaded async using a script

1 messages Β· Page 1 of 1 (latest)

ivory elm
#
public IEnumerator LoadGameScene()
{
    yield return new WaitForSeconds(2);
    AsyncOperation asyncLoad = SceneManager.LoadSceneAsync(sceneToOpen);
    asyncLoad.allowSceneActivation = false;

    while (!asyncLoad.isDone)
    {
        float progress = Mathf.Clamp01(asyncLoad.progress / 0.9f);
        Debug.Log("Loading progress: " + progress * 100 + "%");

        if (asyncLoad.progress >= 0.9f)
        {
            Debug.Log("Scene almost done loading...");

            asyncLoad.allowSceneActivation = true;
        }

        yield return null; // Wait until the next frame to check again
    }

    Debug.Log("Scene loaded successfully!");
}

The code runs but never gets past 0% loaded for whatever reason.

cursive skiff
#

!code

tired pythonBOT
cursive skiff
#

I'd add some logs that print the asyncLoad.progress, as well as some logs on the coroutine entry to make sure you don't have several of these running.

ivory elm
#

Debug.Log("Loading progress: " + progress * 100 + "%");

cursive skiff
#

No it's not. It does some math on it. You should exclude all and any possible factors.

ivory elm
#

the progress says zero and its not loading so I'd be inclined to beleive that its accurate

cursive skiff
#

Well, do it just for sanity.

ivory elm
cursive skiff
#

Again, that's how you should be debugging.

#

Once you have that covered we can move on to next possible culprits.

#

Or use the debugger if you don't want to add logs.

ivory elm
#

its not worth the time to test something so trivial

cursive skiff
#

Then use the debugger.

#

That way you might see some other relevant info.

ivory elm
#

There were earlier errors related to some networking things but they're more of warning than problems with the code

cursive skiff
ivory elm
cursive skiff
#

Take a screenshot of what you see in the debugger

ivory elm
#

I just need some reasons as to whats causing it to not load man I know how to debug

#

Thank you but I'm capable I just don't know what would cause it not to load at all

cursive skiff
ivory elm
#

everything runs

#

some internal unity process isn't working properly

#

thats not something my script debugging can fix

cursive skiff
#

Great, now show what you see in the debugger. The state of the async operation.

ivory elm
cursive skiff
#

Yes, I heard that. That's not what I'm asking.

#

Place a breakpoint in the debugger, F5 a few times and take a screenshot with the async operation fields visible.

ivory elm
#

I understand how to debug

#

That is not the issue

#

my code is perfectly fine

cursive skiff
#

I'm not saying that the issue is in your code. I'm saying that debugging properly would help understand where the issue is.

ivory elm
cursive skiff
#

OK, good luck then

ivory elm
#

I'm asking for reasons the unity scene loading is having issues

#

not for you to tell me to go fix it myself

cursive skiff
#

That's what debugging is for.

ivory elm
cursive skiff
#

There are no common issues though... πŸ€¦β€β™‚οΈ
It's not common for it to not progress, which is exactly why debugging is needed.
And you don't seem do be doing it properly.

cursive skiff
#

Did you try stepping through the code with a debugger or not?

ivory elm
#

The problem is I cannot change my code to fix it

#

My script is fine so theres something else i need to do to fix it

cursive skiff
#

It has nothing to do with your script at this point.

ivory elm
cursive skiff
#

Debugging is not just about your script. It's about understanding what the engine is doing. And you can glimpse at it via the debugger.

cunning oyster
#

I have compared your code to mine, and it is exactly the same functionality (also a VR app). The only difference is I use a string as the scene name (that is of course added to the build settings).

string szToLoad = "Scenes/YourSceneName"
asyncLoad = SceneManager.LoadSceneAsync(szToLoad, LoadSceneMode.Single);
lost steppe
#

I'm suspicious of that

#

Perhaps isDone is now true, causing the while loop to bail out

#

You'd see "Scene loaded successfully!" get logged, but the scene would never be allowed to activate

#

however, the docs suggest that isDone only becomes true once you allow the scene to activate

#

so that's not gonna be it

#

Ensure that you don't have multiple async operations running simultaneously. As dlich suggested, check that you don't multiple instances of this coroutine running.

ivory elm
winged grail
# ivory elm Again, thats not really the issue here

It looks like it could be masking the issue to me. Building for VR runs on android. So iirc your debug message (float * int) converts to an int (always looks like progress is 0 in your debug messages, even when it isnt). But as you aren't looking for debug advice, ill step out and let others weigh in.

#

In of itself it looks fine though without seeing the rest of the code and making sure it isnt canceling or double triggering etc.

#

Also yeah its not too far off from what I use for finding in/out between scene transitions in all our VR games

#

My other suggestion is put a bool in there. _isLoading or something and skip the coroutine when true. Its easy to triple trigger a scene load with VR controllers etc. Iirc that freezes the loader at 0.

ivory elm
winged grail
ivory elm
ivory elm
winged grail
#

Hmm interesting

ivory elm
# winged grail Hmm interesting

I just changed it to opening the scene without async with the one line scene opening method and thats working fine with my scene transitions that are just fading to black so I'll just probably use that for now unless it becomes an issue πŸ€·β€β™‚οΈ

cursive skiff
#

Now you're gonna say that it doesn't matter anymore, because the issue is solved, but it's not.
You just gave up on async loading.

ivory elm
ivory elm
#

I tried to achive that goal with async loading but since it was causing issues its no longer a fitting solution to the issue

cunning oyster
#

Fading out to black, and in to the new scene was my solution too. That's the only way in VR you can fool someone that the 90Hz is kept during scene transitions. Because even with async load (which works for me), there are dips that could feel bad for the player... So no loading-screens in my game, just black.

I do however pause the game with timescale=0 and do the last init/loading/generating of the level after reaching 90% while still having a black screen so things doesn't pop up before play can take place and I set timescale=1.0.

median veldt
#

I like how half life alyx does loading but we dont have that kind of control over scene loading πŸ™

ivory elm
#

I just fade the alpha of its material in and out and it works really well

vast crater
#

Can you show the code that calls the LoadGameScene method?

cunning oyster
median wing
#

Like an Don'tDestroyOnLoad canvas

cunning oyster
#

Probably, but this way was easiest to know it will work. Hiding everything behind it in all angles.

ivory elm
median veldt
#

The normal way would to have something in UI to obscure what's loading.
However for VR you may want an alternative camera to show some simple scene + text while loading like HL:A does.

median wing
#

like, I need to load and show another scene WHILE also background-loading another scene(the next level) and after finishing the loading, transition to the next scene. All done smoothly, or quasi-smoothly.

median veldt
#

huh? why do you think this is harder to do?

#

Anyway whatever you show during loading is meant to be simple so its fast to load and has a small impact during loading

#

normally something in UI is the solution. VR is the outlier

median wing
#

yeah for sure. I use a video player to do the trick.

#

mainly I build PC and sometimes mobile games

#

and have a bit of experience building a VR game for my friend's Oculus

#

but not a full-fledged one

cunning oyster
#

I don't think you can uphold 90 FPS during loading in Unity. So in VR the image would move with the head part of the time and look and feel bad.

median wing
#

probabaly...

#

but I don't think it can uphold even 60 FPS on a decent i7-4770, my old PC.

ivory elm
#

You can have a loading screen for before the screen changes if it takes a long time but for the scene transition itself you can't really show anything

#

So no matter what you'd still have to fade to black or white or just let the display do whatever and don't fade during a transition

median veldt
#

You can if you use additive scene loading or don't destroy on load to keep this extra loading scene stuff visible.
If we load the scene async that should give time for this to show correctly