Forum rules - please read before posting.

Preloading scene not working when using addressable

Hi there,
not sure if I'm missing something but if I try to preload an addressable scene using the action Scene->Switch with the option Don't change scene just preload data selected, nothing happens. The scene is not preloaded and it takes the same exact amount of time to switch to that scene regardless if I use that action or not.
Everything works as expected if the scene I'm trying to preload/switch to is not an addressable, the scene is loading in background (I can see it in the Hierarchy) and the switch is almost immediate (both in build and in the editor), but none of this happens with addressable.
Is there something I need to do to make it work or it's just not possible to preload an addressable scene?
Thanks for any help!
I'm on Unity 2021.3.20f1 and AC 1.75.1

Comments

  • The preloading of Addressable scenes is possible in the latest release - you'll need to update your AC version.

  • edited March 2023

    Thanks Chris, this is the answer I was scared to receive :D
    I tried updating to the latest release a few days ago but had to revert back as I'm having a weird issues with mouse failing to detect being over hotspot.
    I have a script handling most of the interactions that is checking KickStarter.playerInteraction.IsMouseOverHotspot () but in the new release most of the time it's not becoming true even if I'm over an HotSpot. Did something change with this? Could not find anything in the release notes

  • Nothing springs immediately to mind. Is your Hotspot ray length a suitable distance?

    Place Debug.Log statements inside that function to try to work out why it's returning false - it'll run two separate raycasts depending on if you're in 2D or 3D.

  • edited March 2023

    I didn't change ray length from the default 100. Tried changing it to 10 or to 200 but always having the same inconsistent behavior.
    I put a Debug.Log statement on updating and (KickStarter.playerInteraction.IsMouseOverHotspot())is becoming true in an apparently random way, most of the time it becomes true if my mouse is in the farthest position, and it's false in the closest. But as told this changes a lot, sometimes it never turns true.
    Game is 3d see this picture as an example (hotspot is over the whole carpet)
    (
    These are my settings:

    and I made sure Hotspots are in the Default layer

  • I take it the camera is fixed in that screenshot, so the same camera position results in true/false based only on the cursor position.

    If you nudge the carpet up a little, does the true/false boundary remain in-place on the screen, or does it also move up?

    Check for any colliders on the Default layer that may be blocking the Hotspot.

    What's your "Input method" set to, and are you overriding the cursor position with a custom script?

  • Camera is a draggable 3rd person camera and it was not moving while I took that screenshot, I just move the mouse pointer and not clicking.
    Nudging the carpet HS a bit higher the true/false border remain basically the same, also changing the camera angle the true part is always the same shown in the screenshot.
    I already made sure there aren't any colliders in the default layer and "Input method" is set to "Mouse and KeyBoard" and I do not override cursor position.
    Also would like to remind you that everything works flawlessly with AC 1.75.1 but as soon as I update it to 1.76 hotspot detection starts to fail

  • Here's another example. In the first screenshot you can clearly see the hotspot:

    This second one is made running the game, the green spot is the only one over which (KickStarter.playerInteraction.IsMouseOverHotspot())turns True:

  • I think I'll need to see this for myself to get to the bottom of it. Can you PM me a .unitypackage containing a typical scene (along with any prefab dependencies), your game's Managers, and the script you're using?

  • Sent a link to the project via PM. Thanks in advance!

  • Hey Chris, I've updated to AC 1.76.3 as we've now solved the MouseIsOverHotspot issue, but unfortunately preloading addressable scenes seems to be broken.
    Everything works fine in the Editor, the scene is being loaded (I can see it in the hierarchy), switching is very fast and everything is loaded and visible but in build (tested on both WebGL and Android) it looks like assets are not being loaded at all, as nothing is visible (besides menus and the few things that are in the Default group).
    This happens with use loading scene not enabled. Enabling it makes preloading being useless since, as soon as it switches to the loading scene, the preloaded one is being unloaded and loaded again ending to take the usual time to switch to the next scene (this is visible in the editor too).
    Everything is visible and loaded if i remove the preload scene action, regardless the use of the loading scene.
    Save assets references with Addressables?, Load scene asynchronously and Load scenes form Addressables are enabled and AddressableIsPresent is defined. Is there any steps I missed?
    Thanks!

  • it looks like assets are not being loaded at all, as nothing is visible (besides menus and the few things that are in the Default group).

    Is this to say the scene itself is not loaded upon switching, after preloading it? What specifically is seen?

    AC doesn't handle the process differently when in a build vs the Editor - the behaviour may be related to the Addressables system. Are other Addressable scenes loading, and have you re-built your Addressables package after switching the target platform?

    See if you can get an output of the Unity player log - it may share some details as to what's going on.

  • I've rebuilt Addressable package many times but with no luck.
    Also, not only other addressable scenes work but the same scene works fine if not preloaded and it's broken if I preload it. This is the scenario: if it's the first time one plays the game, the play button brings him to an intro scene, during this scene the main game scene is preloaded, at the end of the intro game switches to the main game scene and this is what you see:

    Going back to the main menu scene and pressing play it switches straight to the game scene, without preloading, and everything is visible:

    Same happens with every scene, if I try to preload the intro scene in the main menu, I can only see the text written by the menu but none of the objects, sprites, textures etc.
    All my scene are AC scenes, the very first two scenes (splash and main menu) are in the build settings while all the others are Addressables.
    I've switched to Desktop platform, rebuilt package and still having the same exact behavior. Not sure what I need to look in the player log, attaching it here in case you can see something
    Thanks as always for your time.

  • Thanks for the details.

    My hunch is that this is related to Addressables itself. From my own testing, it seems that preloading an Addressable scene requires that the assets within also be marked as Addressables.

    As a test, try creating a fresh scene with simple Planes/Cubes that don't rely on any assets or prefabs, convert it into an AC scene, and use that in place of your main scene. Does that load correctly?

  • As I suspected this still doesn't work, I am afraid it may be something else.
    Here are the results of my test:
    I created this very simple scene with a couple of cubes, a sphere, a plane, some lights. Put a material on one cube:

    As before, main menu preloads the test scene and that's the result after switching:

    If switching without preloading this is how the scene looks like:

  • Yes - that's the behaviour I was getting. On my end, this was fixed by making the Materials themselves Addressable as well.

  • Unfortunately this still does not work for me. Besides the fact that marking every assets of my main game scene is not feasible, I made a test with my intro scene that is basically as simple as the test scene above: one prefab and a couple of game objects and textures. I marked all textures, materials and prefab as addressables and put them in the same group as the scene but the scene is completely white if preloaded. I also got hundreds of "Cannot draw camera borders because no Fade texture is assigned in the MainCamera!" warning. Made the black.png texture of the camera an Addressable but still having the warning.

    Anyway I kind of found a workaround for me by not relying on AC for this. I added this script to a loadingBox GameObject:

        using UnityEngine;
        using UnityEngine.AddressableAssets;
        using UnityEngine.ResourceManagement.AsyncOperations;
        using UnityEngine.ResourceManagement.ResourceProviders;
    
        public class ScenePreloader : MonoBehaviour
        {
            public AssetReference GameScene;
            private AsyncOperationHandle<SceneInstance> sceneLoadOperation;
    
            public void LoadGame()
            {
                sceneLoadOperation = Addressables.LoadSceneAsync(GameScene, UnityEngine.SceneManagement.LoadSceneMode.Single, false);
                //sceneLoadOperation.Completed += SceneLoadComplete;
            }
            public void ActivateLoadedScene()
            {
                if (sceneLoadOperation.Status == AsyncOperationStatus.Succeeded)
                {
                    sceneLoadOperation.Result.ActivateAsync();
                }
            }
        } 
    

    I'm calling LoadGame during the intro sequence by sending a custom message to the Object, and afterwards I activate the scene with ActivateLoadedScene
    Everything works as expected and is visible.
    This cannot obviously be used when loading a game as AC uses its own way to load and activate scene and but for the moment it can be an acceptable compromise for me, and maybe can help you a bit to identify the issue.

  • Thanks for the details.

    The code you're running is effectively what AC is also running, albeit simplified. I'll look into this and see if there's an issue somewhere.

  • edited April 2023

    I believe I've determined the issue, and is indeed AC-related.

    Apologies for the hassle, and thank you for the details - I will address(able) it.

  • Great, no need to apologise, glad to have been of help. Thanks so much for addressing it :smiley:

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.