Sync addressables dont work in 2019.3.15f, addressables version 1.9.2
Getting the following error in the build:
NullReferenceException: Object reference not set to an instance of an object
at UnityEngine.ResourceManagement.AsyncOperations.InitalizationObjectsOperation.Execute () [0x00014] in C:\Users\tjheuvel\Downloads\Addressables-Sample-master\Advanced\Sync Addressables\Library\PackageCache\[email protected]\Runtime\Initialization\InitializationObjectsOperation.cs:29
at UnityEngine.ResourceManagement.AsyncOperations.AsyncOperationBase`1[TObject].InvokeExecute () [0x00001] in C:\Users\tjheuvel\Downloads\Addressables-Sample-master\Advanced\Sync Addressables\Library\PackageCache\[email protected]\Runtime\ResourceManager\AsyncOperations\AsyncOperationBase.cs:413
at UnityEngine.ResourceManagement.AsyncOperations.AsyncOperationBase`1[TObject].Start (UnityEngine.ResourceManagement.ResourceManager rm, UnityEngine.ResourceManagement.AsyncOperations.AsyncOperationHandle dependency, DelegateList`1[T] updateCallbacks) [0x00076] in C:\Users\tjheuvel\Downloads\Addressables-Sample-master\Advanced\Sync Addressables\Library\PackageCache\[email protected]\Runtime\ResourceManager\AsyncOperations\AsyncOperationBase.cs:407
at UnityEngine.ResourceManagement.ResourceManager.StartOperation[TObject] (UnityEngine.ResourceManagement.AsyncOperations.AsyncOperationBase`1[TObject] operation, UnityEngine.ResourceManagement.AsyncOperations.AsyncOperationHandle dependency) [0x00001] in C:\Users\tjheuvel\Downloads\Addressables-Sample-master\Advanced\Sync Addressables\Library\PackageCache\[email protected]\Runtime\ResourceManager\ResourceManager.cs:411
at UnityEngine.AddressableAssets.Initialization.InitializationOperation.CreateInitializationOperation (UnityEngine.AddressableAssets.AddressablesImpl aa, System.String playerSettingsLocation, System.String providerSuffix) [0x000c5] in C:\Users\tjheuvel\Downloads\Addressables-Sample-master\Advanced\Sync Addressables\Library\PackageCache\[email protected]\Runtime\Initialization\InitializationOperation.cs:59
at UnityEngine.AddressableAssets.AddressablesImpl.InitializeAsync (System.String runtimeDataPath, System.String providerSuffix, System.Boolean autoReleaseHandle) [0x00110] in C:\Users\tjheuvel\Downloads\Addressables-Sample-master\Advanced\Sync Addressables\Library\PackageCache\[email protected]\Runtime\AddressablesImpl.cs:394
at UnityEngine.AddressableAssets.AddressablesImpl.InitializeAsync () [0x00001] in C:\Users\tjheuvel\Downloads\Addressables-Sample-master\Advanced\Sync Addressables\Library\PackageCache\[email protected]\Runtime\AddressablesImpl.cs:403
at UnityEngine.AddressableAssets.Addressables.InitializeAsync () [0x00001] in C:\Users\tjheuvel\Downloads\Addressables-Sample-master\Advanced\Sync Addressables\Library\PackageCache\[email protected]\Runtime\Addressables.cs:270
at SyncAddressables.Init () [0x00001] in C:\Users\tjheuvel\Downloads\Addressables-Sample-master\Advanced\Sync Addressables\Assets\SyncAddressables\SyncAddressables.cs:19
Looks like it can't make it to get the result in time in one frame. If you use the code from examples
var handle = Addressables.LoadAssetAsync<CustomScriptableObject>("key");
var so = handle.Result;
a null reference will be returned. There's no way to wait for async operation to complete except using coroutines and Completed event callback:
Addressables.LoadAssetAsync<CustomScriptableObject>("key").Completed += handle => Debug.Log(handle.Result.name)
Same for Addressables.InstantiateAsync("key")
Addressables really suffer without synchronous methods. For instance if you init a logic inside a static method marked with RuntimeInitializeOnLoadMethodAttribute and you want it to be executed before any Awake(). So you're trying to load assets with addressables there and you can't do that way. When the async operation completed and it's Completed callback invoked, the train is already far ahead of Awakes.
Thus using Addressables possesses the code with Completed lambda callbacks with bunch of closure allocations everywhere if you're not using async approach in your project in general
we've updated the samples to addressables 1.15.1 and it seems to be running fine. If you continue to get errors, please let us know
Addressables 1.16.15, Unity 2020.1.10f1:
SyncAddressables.Instantiate (System.Object key, UnityEngine.Transform parent, System.Boolean instantiateInWorldSpace) (at Assets/SyncAddressables/SyncAddressables.cs:57)
spawner.FixedUpdate () (at Assets/spawner.cs:34)
Hi @truenoob141 thanks for reporting this issue! The SyncAddressables project has been removed from the repository. The main package now supports synchronous loading https://docs.unity3d.com/Packages/[email protected]/manual/SynchronousAddressables.html#synchronous-workflow