Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Simple addressables use case help

Discussion in 'Addressables' started by Oshigawa, Jan 15, 2020.

  1. Oshigawa

    Oshigawa

    Joined:
    Jan 26, 2016
    Posts:
    362
    Hi everyone,

    I'm trying to avoid resources since addressables look like a real deal compared to resources since i don't need to put stuff in separate folders and so on. Unfortunately, documentation is still quite unclear so i'm seeking clarification and advice via forum.

    My use case is quite simple, i need shorter loading times, i.e. what i need is to label the addressables (prefabs, audio clips, textures, variables) as, for example, level 1, level 2 and so on and load them all at once as needed (when loading level, for example).

    I just need good old "load stuff in memory for next level now", not pulling assets from web server or stuff like that.

    Also, using Sprite Atlases in a similar manner would be great, just loading the whole Sprite Atlas with sprites, ready to use, without the need to address each and every sprite after loading.

    Any advice is appreciated, cheers.
     
    Last edited: Jan 16, 2020
  2. Oshigawa

    Oshigawa

    Joined:
    Jan 26, 2016
    Posts:
    362
    I tried something simple like Addressables.LoadAssetsAsync<GameObject>("Label", null), but all get is Exception encountered in operation Resource<GameObject>(PrefabName.prefab): Unknown error in AsyncOperation for each prefab.

    I haven't changed anything regarding default build target, local build and local load path. Addressables version is 1.5.0.
     
    Last edited: Jan 16, 2020
  3. Oshigawa

    Oshigawa

    Joined:
    Jan 26, 2016
    Posts:
    362
    I tried updating to 1.5.1, now i get something completely different.

    Code (CSharp):
    1. Exception encountered in operation Dependencies: Unknown error in AsyncOperation
    Code (CSharp):
    1. Exception encountered in operation UnityEngine.ResourceManagement.ResourceManager+CompletedOperation`1[System.Collections.Generic.IList`1[UnityEngine.Object]], result='', status='Failed': Unknown error in AsyncOperation
    Code (CSharp):
    1. Exception encountered in operation Dependencies - Chain<IList`1,IList`1>: ChainOperation of Type: System.Collections.Generic.IList`1[UnityEngine.Object] failed because dependent operation failed
    Code (CSharp):
    1. Exception encountered in operation UnityEngine.AddressableAssets.Initialization.InitializationOperation, result='', status='Succeeded' - Chain<IList`1>: ChainOperation of Type: System.Collections.Generic.IList`1[UnityEngine.Object] failed because dependent operation failed
    2. ChainOperation of Type: System.Collections.Generic.IList`1[UnityEngine.Object] failed because dependent operation failed
    Code (CSharp):
    1.  
    2. NullReferenceException: Object reference not set to an instance of an object
    3.   at AddressablesLoader+<>c.<Update>b__1_0 (UnityEngine.ResourceManagement.AsyncOperations.AsyncOperationHandle`1[TObject] objects) [0x00002] in C:\Users\Krmko\Desktop\2018.3.7 - 14.01\Assets\AddressablesLoader.cs:21
    4.   at DelegateList`1[T].Invoke (T res) [0x00038] in C:\Users\Krmko\Desktop\2018.3.7 - 14.01\Library\PackageCache\com.unity.addressables@1.5.1\Runtime\ResourceManager\Util\DelegateList.cs:69
    5. UnityEngine.DebugLogHandler:Internal_LogException()
    6. UnityEngine.DebugLogHandler:LogException(Exception, Object)
    7. UnityEngine.Logger:LogException(Exception, Object)
    8. UnityEngine.Debug:LogException(Exception)
    9. DelegateList`1:Invoke(AsyncOperationHandle`1) (at C:\Users\Krmko\Desktop\2018.3.7 - 14.01\Library\PackageCache\com.unity.addressables@1.5.1\Runtime\ResourceManager\Util\DelegateList.cs:73)
    10. UnityEngine.ResourceManagement.AsyncOperations.AsyncOperationBase`1:InvokeCompletionEvent() (at C:\Users\Krmko\Desktop\2018.3.7 - 14.01\Library\PackageCache\com.unity.addressables@1.5.1\Runtime\ResourceManager\AsyncOperations\AsyncOperationBase.cs:322)
    11. UnityEngine.ResourceManagement.AsyncOperations.AsyncOperationBase`1:UnityEngine.ResourceManagement.AsyncOperations.IAsyncOperation.InvokeCompletionEvent() (at C:\Users\Krmko\Desktop\2018.3.7 - 14.01\Library\PackageCache\com.unity.addressables@1.5.1\Runtime\ResourceManager\AsyncOperations\AsyncOperationBase.cs:459)
    12. UnityEngine.ResourceManagement.ResourceManager:ExecuteDeferredCallbacks() (at C:\Users\Krmko\Desktop\2018.3.7 - 14.01\Library\PackageCache\com.unity.addressables@1.5.1\Runtime\ResourceManager\ResourceManager.cs:791)
    13. UnityEngine.ResourceManagement.ResourceManager:Update(Single) (at C:\Users\Krmko\Desktop\2018.3.7 - 14.01\Library\PackageCache\com.unity.addressables@1.5.1\Runtime\ResourceManager\ResourceManager.cs:818)
    14. MonoBehaviourCallbackHooks:Update() (at C:\Users\Krmko\Desktop\2018.3.7 - 14.01\Library\PackageCache\com.unity.addressables@1.5.1\Runtime\ResourceManager\Util\MonoBehaviourCallbackHooks.cs:19)
    15.  
     
  4. Oshigawa

    Oshigawa

    Joined:
    Jan 26, 2016
    Posts:
    362
    Well, i think i'll give up for the time being and use resources instead.

    I tried cleaning the build and building again, but nothing, all i get is Exception encountered in operation Resource<GameObject>(PrefabName.prefab): Unknown error in AsyncOperation over and over again. Load and build paths are default.

    I tried removing all the labels from all the addressables except one object for testing and i get this:

    Code (CSharp):
    1. Exception encountered in operation Resource<GameObject>(Provoker.prefab): Unknown error in AsyncOperation
    2. (Filename: C:\buildslave\unity\build\Runtime/Export/Debug.bindings.h Line: 45)
    3.  
    4. Exception encountered in operation UnityEngine.AddressableAssets.Initialization.InitializationOperation, result='', status='Succeeded' - Chain<GameObject>: ChainOperation of Type: UnityEngine.GameObject failed because dependent operation failed
    5. Unknown error in AsyncOperation
    However, i tried a fresh project in latest stable 2019 version with a simple object and it works (as in no errors, i haven't tested it with callback or instantiation).

    So, i tried making an empty prefab (to see if there's something problematic with my prefabs) in 2018.3.7 and put only that one under the label for loading, cleaned the build, built again, but it still fails.

    Ok, maybe it will go away if update Unity. I installed the latest 2018 LTS, cleaned and rebuilt. Same.

    I can't try 2019 since some of the stuff i use probably won't work in it.

    This really sucks, hope it will sort out.
     
    Last edited: Jan 17, 2020
  5. MiguelGram

    MiguelGram

    Joined:
    Jun 19, 2019
    Posts:
    2
    I'm having exactly the same issue when building for android and I'm curious to know how to solve it
     
  6. MiguelGram

    MiguelGram

    Joined:
    Jun 19, 2019
    Posts:
    2
    I solved it.
    My case I was building the addressables in the wrong platform.
    I also had a bug in my code where I was instantiating loaded assets in the same frame where I initialize the addressables framework. I switched from LoadAsset to InstatiateAsync and worked like a charm
     
  7. Oshigawa

    Oshigawa

    Joined:
    Jan 26, 2016
    Posts:
    362
    I have a separate scene that starts before everything else for loading the addressables, build is for the proper platform and i don't use instantiation, just need to load game objects into memory before i pool them.

    Strange.
     
    Last edited: Jan 19, 2020
  8. Oshigawa

    Oshigawa

    Joined:
    Jan 26, 2016
    Posts:
    362
    Thanks to great @BansheeGz the issue is solved.

    --
    This issue is easily reproducible on a new, empty project
    Here is a link to the project: https://drive.google.com/open?id=1r7pM_l8X9vQPSHDYf7K9BIIxGMNencsT
    It's almost empty

    Steps to reproduce:
    1) Create a new project and import Addressables
    2) Open SampleScene, add a cube, make a prefab out of it and mark it as Addressables
    3) Chose DefaultLocalGroup asset (Assets\AddressableAssetsData\AssetGroups\Default Local Group.asset), press "Add Schema" and chose "Resources and Built In Scenes"
    4) Open "Addressables Groups" (Window->Asset Management->Addressables->Groups), open PlayModeScript dropdown list and chose "Use existing build" option, then build it (Build->NewBuild->DefaultBuildScript)
    5) Create LoadAddressable.cs file with such content

    Code (CSharp):
    1.     using UnityEngine;
    2.     using UnityEngine.AddressableAssets;
    3.     using UnityEngine.ResourceManagement.AsyncOperations;
    4.    
    5.     public class LoadAddressable : MonoBehaviour
    6.     {
    7.         public string Address;
    8.         void Start()
    9.         {
    10.             Addressables.LoadAssetAsync<GameObject>(Address).Completed += Completed;
    11.         }
    12.    
    13.         private void Completed(AsyncOperationHandle<GameObject> handle)
    14.         {
    15.             print("Loaded object=" + handle.Result);
    16.         }
    17.     }
    18.  
    attach it to any GameObject, set Address parameter to the address of previously created prefab and run the scene.

    2 errors will be printed to the console (one without stack trace and another with stack trace)

    # 1:

    Code (CSharp):
    1.     Exception encountered in operation Resource<GameObject>(Cube.prefab): Unknown error in AsyncOperation
    2.     UnityEngine.AsyncOperation:InvokeCompletionEvent()
    3.    
    4.  
    # 2:

    Code (CSharp):
    1.    
    2.     Exception encountered in operation UnityEngine.AddressableAssets.Initialization.InitializationOperation, result='', status='Succeeded' - Chain<GameObject>: ChainOperation of Type: UnityEngine.GameObject failed because dependent operation failed
    3.     Unknown error in AsyncOperation
    4.     UnityEngine.ResourceManagement.ChainOperationTypelessDepedency`1:OnWrappedCompleted(AsyncOperationHandle`1)
    5.     DelegateList`1:Invoke(AsyncOperationHandle`1) (at Library/PackageCache/com.unity.addressables@1.6.0/Runtime/ResourceManager/Util/DelegateList.cs:69)
    6.     UnityEngine.ResourceManagement.ResourceManager:Update(Single)
    7.     MonoBehaviourCallbackHooks:Update() (at Library/PackageCache/com.unity.addressables@1.6.0/Runtime/ResourceManager/Util/MonoBehaviourCallbackHooks.cs:19)
    8.    
    9.  
    The reason is- because build script creates 2 locations for the asset (Resources and Bundled) and can not load from Resources location.

    2 Ways to resolve the issue:
    1) Remove "Resources and Built In Scenes" schema, which was previously added
    2) Toggle off both "Include Resources folders" and "Include Build Settings Scenes" parameters

    I'm not sure if it's a bug or not, maybe we are not supposed to add this schema in the first place, I do not know