- Home /
Issue in Unity Addressable
using UnityEngine;
using UnityEngine.AddressableAssets;
using UnityEngine.ResourceManagement.AsyncOperations;
namespace Addressable
{
public class Address : MonoBehaviour
{
public AssetReference Ship;
private GameObject _s;
[SerializeField] private Transform pos;
public void Start()
{
Ship.LoadAssetAsync<GameObject>().Completed += OnLoadDone;
if (_s != null)
{
Instantiate(_s, pos.position, pos.rotation);
}
else
{
Debug.Log("Null");
}
}
private void OnLoadDone(AsyncOperationHandle<GameObject> obj)
{
Debug.Log(obj.Status);
_s = obj.Result;
//Instantiate(obj.Result, pos.position, pos.rotation);
}
}
}
Error Exception encountered in operation UnityEngine.AddressableAssets.Initialization.InitializationOperation, result='', status='Succeeded' - Chain: ChainOperation of Type: UnityEngine.GameObject failed because dependent operation failed Exception of type 'UnityEngine.AddressableAssets.InvalidKeyException' was thrown., Key=bd468827bc52a634f962c947478abb3a UnityEngine.ResourceManagement.ChainOperation`2:OnWrappedCompleted(AsyncOperationHandle`1) DelegateList`1:Invoke(AsyncOperationHandle`1) (at Library/PackageCache/com.unity.addressables@1.1.7/Runtime/ResourceManager/Util/DelegateList.cs:69) UnityEngine.ResourceManagement.ResourceManager:Update(Single) MonoBehaviourCallbackHooks:Update() (at Library/PackageCache/com.unity.addressables@1.1.7/Runtime/ResourceManager/Util/MonoBehaviourCallbackHooks.cs:19)
Answer by ThomasRodriguez · Oct 30, 2019 at 11:26 AM
Hi,
I guess we're following the same manual at https://docs.unity3d.com/Packages/com.unity.addressables@1.1/manual/AddressableAssetsGettingStarted.html .
I'm also trying to understand AddressableAssets, and saw the same error message.
By trying some stuff around, it seems to me that the problem comes from addressables references in the editor. Make sure to select the correct addressable type in the dropdown menu for your Ship AddressReference. If for example you try Ship.LoadAssetAsync<GameObject>().Completed += OnLoadDone;
but your Ship asset isn't a GameObject, the error will raise.
Also it appears that sometimes when changing the reference from the dropdown menu, especially after changing code in the script, Unity will still raise the error even if the types match.
I found that removing the asset as addressable, making it addressable again, selecting None in the dropdown menu and selecting the correct reference again makes the error go away and the script working.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
How to : Editor.OnPreviewGUI Implementation 0 Answers
Null Reference Exception while trying to access Text Files 1 Answer