Forum rules - please read before posting.

Is it possible to load more than 1 scene for dynamic scene loading with AC?

edited November 2020 in Technical Q&A

I'm trying to achieve a smooth instant scene transition between scenes in my 2d game.
I saw few tutorials where they use LoadLevelAdditive (obsolete only with prior Unity5.3 ) to make instant scene transitions.


And the second video is with SceneManager.LoadSceneAdditive

Basically you load your first scene and preload or additively load your second scene. When you change to scene 2 you preload scene 3, when you change to scene 3 you preload scene 4 and unload scene 2 and so on.
Is there a way to achieve this with AC?

I also found Engine: Change scene with Don't chnage scene, just Preload data actionlist, what does it do can this help me? In AC scripting-guide it says :

Preloads a scene. Preloaded data will be discarded if the next scene opened is the same a the one preloaded

So if I in scene 1 I preload scene 2 and change to it it won't work since it gets discarded.

Comments

  • AC additive loading is possible by checking Load scenes additively? in the Settings Manager. What Unity and AC versions are you now using?

    Preloaded data will be discarded if the next scene opened is the same a the one preloaded

    That should read not the same. Data can only be preloaded for one scene at a time - so preloading a given scene should always be followed by the opening of that same scene.

    Following your example, you can place a Scene: Switch Action in scene 2's OnStart cutscene to preload scene 3. You can then use another such Action (without preloading) when ready to switch to scene 3.

    Alternatively, you can add in scene 3 and remove scene 2 at a later time. This can be done with the Scene: Add or remove Action.

  • I decided to stick to my old Unity 5.24f1 and AC 1.50 f

  • I mispoke above - you can check Load scenes asynchronously? to load scenes asynchronously, not additively.

    For asynchronous loading, i.e. use of the Scene: Add or remove, you will need to use the latest release.

  • edited November 2020

    In AC 1.50f there is Engine: Change scene Don't change scene, just Preload

    Basically I don't want just to add scene 3 to scene 2 and have them together active.

    I want to preload-load scene 3 in the background while the game is being played in scene 2, and keep it inactive until I want to change to scene 3 so instead of loading it, it just becomes active with no loading lags and delays. And then I would quietly preload in background scene 4 and unload scene 2 or 3 ( thought might keep scene 3 in background inactive if a player wants to go back to it)

    So is it possible to preload scene 3 as you said placed OnStart in background while the game is played on scene 2 and keep it in background and inactive.

    How would I activate it? Use Engine: Change scene to 3 and it would instantly become active and the old scene inactive-unloaded?
    Thank you Chris.

  • Yes - as above, you'd use two instance of Engine: Change scene (now Scene: Switch). One to preload it, one two switch to it.

  • edited November 2020

    Ok, here it is:
    Scene 1 OnStart wait tick 0.1 Preload Scene 2
    Click on Hotspot Engine: Change scene to Scene 2
    Scene 2 OnStart wait tick 0.1 Preload Scene 1
    Click on Hotspot Engine: Change scene to Scene 1
    (it doesn't work with out Engine: wait 0.1 I read on this forum)

    It seems like it works and the loading time is lower. Is this right btw?
    However when I try to go to any other scene in the build and in the editor it hangs with no error from console.
    Unity 5.24f1 and AC 1.50 f
    Load scenes asynchronously ? checked

    The other scenes 3-5 are with out OnStart preloads, or any preloads , just scenes.

  • It seems like it works and the loading time is lower. Is this right btw?

    Sounds right.

    However when I try to go to any other scene in the build and in the editor it hangs with no error from console.

    This was a bug fixed in v1.62.3. Try inserting this into the top of the SceneChanger script's LoadLevel function, line 181:

    if (preloadSceneInfo != null && !nextSceneInfo.Matches (preloadSceneInfo))
    {
        if (preloadAsync != null) preloadAsync.allowSceneActivation = true;
        preloadSceneInfo = new SceneInfo ("", -1);
    }
    
  • edited November 2020

    I really appreciate your help.
    Now when I start my game:
    Scene 1 OnStart wait tick 0.1 Preload Scene 2
    Click on Hotspot Engine: Change scene to Scene 3 (has no preload OnStart, clean scene)

    it gives me bellow error

    NullReferenceException: Object reference not set to an instance of an object
    AC.SceneChanger+c__IteratorE.MoveNext () (at Assets/AdventureCreator/Scripts/Game engine/SceneChanger.cs:306)

    but allows me to play on on Scene 3. Also for a little tiny bit scene 2 appears and fades out then a black screen appears and then Scene 3 loaded. I guess it's something to do with starting on Scene 1 that has Preload of Scene 2

    Abd if I go back to Scene 1 it crashes with the same error.

    I thought that Engine: wait 0.1 was a fix the error.

  • Try the following instead:

    if (preloadSceneInfo != null && !nextSceneInfo.Matches (preloadSceneInfo))
    {
        if (preloadAsync != null) preloadAsync.allowSceneActivation = true;
        preloadAsync = null;
        preloadSceneInfo = new SceneInfo ("", -1);
    }
    

    If it still causes a warning, please share the full message as it appears when selected in the Console, as well as your Settings Manager's "Scene loading" section.

    Since you've been making changes to SceneChanger, what is on the line it references, 306?

  • With the new line of code I get all the same what I described previously.
    The error:

    NullReferenceException: Object reference not set to an instance of an object
    AC.SceneChanger+c__IteratorE.MoveNext () (at Assets/AdventureCreator/Scripts/Game engine/SceneChanger.cs:307)

    It refers to while

    private IEnumerator PreloadLevelAsync (SceneInfo nextSceneInfo)
    {
    loadingProgress = 0f;

            preloadSceneInfo = nextSceneInfo;
            preloadAsync = nextSceneInfo.LoadLevelASync ();
            preloadAsync.allowSceneActivation = false;
    
            // Wait until done and collect progress as we go.
            while (!preloadAsync.isDone)
            {
                loadingProgress = preloadAsync.progress;
                if (loadingProgress >= 0.9f)
                {
                    // Almost done.
                    break;
                }
                yield return null;
            }
        }
    
  • I can't recreate such an issue.

    How long does a scene change without preloading take? It sounds like the preloading is still occuring when the scene change is requested.

    Try replacing:

        while (!preloadAsync.isDone)
    

    with:

        while (preloadAsync != null && !preloadAsync.isDone)
    
  • edited November 2020

    The same happens only now no error just a screen freeze ( hangs)
    As soon as I leave the 2 scenes(1 and 2) that have preloads for each other and go to the 3rd scene that has no preload and then go to any scene it hangs.

    Start scene 1 OnStart cutscene preload scene 2 then change to scene 3
    scene 2 appears and fades out, then a black screen appears and then Scene 3 is loaded.
    Why would it do it? It literally loads fast scene 2 then leaves it and then loads scene 3. Shouldn't it discard the data if I go to another scene that wasn't destined to be preloaded?

    But it's fine if I go between scene 1 and 2 which have preloads for each other.
    Do I preload OnStart or Onload or can both ? Tried all the ways anyway, same happens.

    With out any preloads Scene Changes take for some scenes between 3-5 seconds.

    Btw I turned off any Autosaves when I change a scene(I use autosave when I change a scene right before the scene is changed with Engine: Scene change),
    Autosave only adds up up to 2-3 seconds more to the loading of any scene while it is doing it's job.

  • Try replacing both instances of:

    if (nextSceneInfo.Matches (preloadSceneInfo))
    

    with:

    if (preloadAsync != null && nextSceneInfo.Matches (preloadSceneInfo))
    

    If that fails, please send clear steps - with screenshots of the Actions involved - on how to recreate the issue in the simplest way. I've tried based on your description and cannot reproduce the issue.

  • edited November 2020

    I don't know, some weird stuff.
    Sometimes It works in the editor with unchecked Maximize on Play in game tab, but not with it, also inventory disappears for some reason. Doesn't work in the build, just crashes-hangs.
    AC 1.50f Unity 5.2.4f1

    Really simple setup
    Start Scene1 Onstart and OnLoad have this below(tried only Onstart too)
    https://filebin.net/1vdweodmhg9ry3hl/PreloadAction.PNG?t=9ny9c9hf

    Go to Scene2 Onstart and Onload have this below(tried only Onstart too)


    https://filebin.net/yemzr953osrsddqj/PreloadAction1.PNG?t=hv0dk19u

    Now go to ** Scene 3** from any scene and then try to go to absolutely any scene crash-hangs.
    Scene 3 has no preloads , just a clean scene.

    It looks like I can only go between scene 1 and 2.

    Perhaps if you only have 3 sprites in each scene it works fine, but if you have lots of stuff in them it needs more time to preload or it can't discard data in time or something...

    **Btw Chris can you PM me AC 1.50f just in case.
    **
    Cause my Unity and my project crash when I upgrade my project to AC 1.60
    with pop-up the below and I can never launch my Unity at all after( good I have Unity back up with my project)

    The file MemoryStream is corrupted! Remove it and launch unity again.

    Don't look into the problem, it's enough, it's just way confusing with old unity and Ac versions.

    Thank you for your help Chris , AC is still one of the best assets and best support for sure .

  • PM sent.

    Still no luck recreating the issue - but your AC is years out of date, and your Unity version too may well have associated issues.

    I would strongly recommend trying to upgrade again. Your MemoryStream issue is likely a case of needing to delete your project's Library folder (keep a backup, naturally).

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.