Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

LoadSceneAsync and Addressable prefabs in hierarchy

Discussion in 'Addressables' started by FlorianBernard, Feb 17, 2021.

  1. FlorianBernard

    FlorianBernard

    Joined:
    Jun 9, 2015
    Posts:
    165
    I'm encountering a problem that I was not expected: when loading a scene (in "Use Existing Build" mode) with
    Addressables.LoadSceneAsync containing instances (in hierarchy) of prefabs that are addressable and packed in separate bundles, they (the bundles) don't get loaded and sub-assets (meshes, textures etc.) show as "Missing" from MeshFilter components and materials.

    I was expecting Addressables.LoadResourceLocationsAsync as well as LoadSceneAsync handles to return the scene bundle AND any other dependent bundles. But they return ONLY the scene bundle.

    I also tried to use Addressables.LoadResourceLocationsAsync with a list a keys (scene and dependent prefabs), but after using LoadSceneAsync, sub-assets are missing as well (here, I guess bundles are cached but not loaded).

    In short, my goal is pretty simple: if both of my levels, let say "Level1" and "Level2", require the same prefabs, I want them to be downloaded along with "Level1.unity" and then recycled when loading "Level2.unity". This seems, to me, to be a pretty basic usage of the Addressable system.

    Am I missing something or is that by design? Can Addressable assets reside in the hierarchy, or can they only be instantiated? Any help or feedback would be very much appreciated!
     
    Last edited: Feb 17, 2021
  2. Patrick_PS

    Patrick_PS

    Joined:
    Sep 9, 2019
    Posts:
    142
    Before using that mode you have to manually rebuild the asset bundles.
     
  3. LucasHehir

    LucasHehir

    Joined:
    May 7, 2020
    Posts:
    74
    That is pretty interesting, I've often wondered where the seams on what scene bundles decide to include lie, especially with shared resources like this.

    My first point of call would be to iterate through each asset location in the results from LoadResourceLocationsAsync and then iterate through each of those locations dependencies. Ideally, it should be listing the bundles your shared prefabs are contained in too. My guess is they won't be listed.
     
  4. FlorianBernard

    FlorianBernard

    Joined:
    Jun 9, 2015
    Posts:
    165
    Yep, as mentioned in my message, those prefab dependencies are not listed by LoadResourceLocationsAsync when passing the scene address :/

    @dc5774 shared the same problem in an another post (see here).

    Let's hope someone from Unity will share some feedback.

    I later figured that the missing scripts and meshes issue was due to calling an FMOD async method in a coroutine in Start() after the scene loaded. It doesn't make any sense, and I still don't know why, but commenting it out fixed the missing references issue. I would recommend deactivating some of your scripts/assets from the scene trying to isolate the cause.
     
    Last edited: Feb 18, 2021
  5. Resshin27

    Resshin27

    Joined:
    Apr 21, 2018
    Posts:
    31
    Have the same issue, missing meshes on prefabs when I build the game with "Use existing build". Even when I run the game in Editor, meshes on my prefabs are missing with this play mode script.

    Solution anyone?
     
  6. Resshin27

    Resshin27

    Joined:
    Apr 21, 2018
    Posts:
    31
    It seems like I was releasing the AsyncOperationHandle<GameObject> for my prefabs too early. I moved my Addressables.Release() calls to a later stage and my prefabs are back in game. They work as they are supposed to.
    I couldn't catch this earlier as I was using "Use Asset Database" build setup until now.
    @FlorianBernard thanks for the heads up, I almost forgot about my code, and was messing with Addressable settings, schemas, build settings etc. and what not since last 2 hours; except for my code. :oops::oops:
     
    FlorianBernard likes this.