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.
I tried something simple like Addressables.LoadAssetsAsync(“Label”, null), but all get is Exception encountered in operation Resource(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.
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(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:
Exception encountered in operation Resource<GameObject>(Provoker.prefab): Unknown error in AsyncOperation
(Filename: C:\buildslave\unity\build\Runtime/Export/Debug.bindings.h Line: 45)
Exception encountered in operation UnityEngine.AddressableAssets.Initialization.InitializationOperation, result='', status='Succeeded' - Chain<GameObject>: ChainOperation of Type: UnityEngine.GameObject failed because dependent operation failed
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.
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
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.
Open SampleScene, add a cube, make a prefab out of it and mark it as Addressables
Chose DefaultLocalGroup asset (Assets\AddressableAssetsData\AssetGroups\Default Local Group.asset), press “Add Schema” and chose “Resources and Built In Scenes”
Open “Addressables Groups” (Window->Asset Management->Addressables->Groups), open PlayModeScript dropdown list and chose “Use existing build” option, then build it (Build->NewBuild->DefaultBuildScript)
Create LoadAddressable.cs file with such content
using UnityEngine;
using UnityEngine.AddressableAssets;
using UnityEngine.ResourceManagement.AsyncOperations;
public class LoadAddressable : MonoBehaviour
{
public string Address;
void Start()
{
Addressables.LoadAssetAsync<GameObject>(Address).Completed += Completed;
}
private void Completed(AsyncOperationHandle<GameObject> handle)
{
print("Loaded object=" + handle.Result);
}
}
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:
Exception encountered in operation Resource<GameObject>(Cube.prefab): Unknown error in AsyncOperation
UnityEngine.AsyncOperation:InvokeCompletionEvent()
2:
Exception encountered in operation UnityEngine.AddressableAssets.Initialization.InitializationOperation, result='', status='Succeeded' - Chain<GameObject>: ChainOperation of Type: UnityEngine.GameObject failed because dependent operation failed
Unknown error in AsyncOperation
UnityEngine.ResourceManagement.ChainOperationTypelessDepedency`1:OnWrappedCompleted(AsyncOperationHandle`1)
DelegateList`1:Invoke(AsyncOperationHandle`1) (at Library/PackageCache/com.unity.addressables@1.6.0/Runtime/ResourceManager/Util/DelegateList.cs:69)
UnityEngine.ResourceManagement.ResourceManager:Update(Single)
MonoBehaviourCallbackHooks:Update() (at Library/PackageCache/com.unity.addressables@1.6.0/Runtime/ResourceManager/Util/MonoBehaviourCallbackHooks.cs:19)
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:
Remove “Resources and Built In Scenes” schema, which was previously added
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