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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Bug Asset exists with main Type=GameObject, which is not assignable from the requested Type=GameObject

Discussion in 'Addressables' started by UnityDEVDEP, Jun 27, 2022.

  1. UnityDEVDEP

    UnityDEVDEP

    Joined:
    Feb 16, 2022
    Posts:
    3
    Hello.
    When I try to call the Addressables.LoadAssetAsync<GameObject> method, I get the following error:
    Code (csharp):
    1.  
    2. UnityEngine.AddressableAssets.InvalidKeyException: Exception of type 'UnityEngine.AddressableAssets.InvalidKeyException' was thrown. Could not load Asset with GUID=405a06907cca941dba8b5f33c7e25b38, Path=Assets/GameResources/Features/Factory/Prefabs/TestDragon.prefab. Asset exists with main Type=UnityEngine.GameObject, which is not assignable from the requested Type=UnityEngine.GameObject
    3. UnityEngine.ResourceManagement.AsyncOperations.AsyncOperationBase`1/<>c__DisplayClass57_0<UnityEngine.AddressableAssets.ResourceLocators.IResourceLocator>:<add_CompletedTypeless>b__0 (UnityEngine.ResourceManagement.AsyncOperations.AsyncOperationHandle`1<UnityEngine.AddressableAssets.ResourceLocators.IResourceLocator>)
    4. DelegateList`1<UnityEngine.ResourceManagement.AsyncOperations.AsyncOperationHandle`1<UnityEngine.AddressableAssets.ResourceLocators.IResourceLocator>>:Invoke (UnityEngine.ResourceManagement.AsyncOperations.AsyncOperationHandle`1<UnityEngine.AddressableAssets.ResourceLocators.IResourceLocator>) (at Library/PackageCache/com.unity.addressables@1.19.19/Runtime/ResourceManager/Util/DelegateList.cs:69)
    5. UnityEngine.AddressableAssets.Initialization.InitializationOperation/<>c__DisplayClass18_0:<LoadContentCatalogInternal>b__0 (UnityEngine.ResourceManagement.AsyncOperations.AsyncOperationHandle`1<UnityEngine.AddressableAssets.ResourceLocators.IResourceLocator>)
    6. DelegateList`1<UnityEngine.ResourceManagement.AsyncOperations.AsyncOperationHandle`1<UnityEngine.AddressableAssets.ResourceLocators.IResourceLocator>>:Invoke (UnityEngine.ResourceManagement.AsyncOperations.AsyncOperationHandle`1<UnityEngine.AddressableAssets.ResourceLocators.IResourceLocator>) (at Library/PackageCache/com.unity.addressables@1.19.19/Runtime/ResourceManager/Util/DelegateList.cs:69)
    7. UnityEngine.ResourceManagement.ChainOperation`2<UnityEngine.AddressableAssets.ResourceLocators.IResourceLocator, UnityEngine.AddressableAssets.ResourceLocators.ContentCatalogData>:OnWrappedCompleted (UnityEngine.ResourceManagement.AsyncOperations.AsyncOperationHandle`1<UnityEngine.AddressableAssets.ResourceLocators.IResourceLocator>)
    8. DelegateList`1<UnityEngine.ResourceManagement.AsyncOperations.AsyncOperationHandle`1<UnityEngine.AddressableAssets.ResourceLocators.IResourceLocator>>:Invoke (UnityEngine.ResourceManagement.AsyncOperations.AsyncOperationHandle`1<UnityEngine.AddressableAssets.ResourceLocators.IResourceLocator>) (at Library/PackageCache/com.unity.addressables@1.19.19/Runtime/ResourceManager/Util/DelegateList.cs:69)
    9. UnityEngine.ResourceManagement.ResourceManager:Update (single)
    10. MonoBehaviourCallbackHooks:Update () (at Library/PackageCache/com.unity.addressables@1.19.19/Runtime/ResourceManager/Util/MonoBehaviourCallbackHooks.cs:26)
    11.  
    Unity Editor: 2021.3.4f1
    Addressables: 1.19.19
     
  2. UnityDEVDEP

    UnityDEVDEP

    Joined:
    Feb 16, 2022
    Posts:
    3
    I got all the keys from Addressables.ResourceLocators and in the search there is a loaded asset with such a key
     

    Attached Files:

  3. zachlindblad

    zachlindblad

    Joined:
    Sep 29, 2016
    Posts:
    39
    Just got the same error today trying to load from an AssetReference

    Code (CSharp):
    1. UnityEngine.AddressableAssets.InvalidKeyException: Exception of type 'UnityEngine.AddressableAssets.InvalidKeyException' was thrown. Could not load Asset with GUID=549302ad753399c4fb334b47fa16333f, Path=<PATH_OF_ASSET>. Asset exists with main Type=<TYPE_X>, which is not assignable from the requested Type=<TYPE_X>
    called from:

    saveData.scriptableObjectReference.LoadAssetAsync<TYPE_X>().WaitForCompletion();

    Addressables v. 1.19.19
    Unity Editor v. 2020 LTS

    Has anyone else had this error? I'm not doing anything too crazy with addressables, was just attempting to serialize an assetReference to json then deserialize and load the asset as a test.
     
  4. EnjeruDarari

    EnjeruDarari

    Joined:
    Jul 6, 2020
    Posts:
    6
    Same problem
    Unity Editor: 2021.3.4f1
    Addressables: 1.19.19
    Hash Provider
     
  5. zachlindblad

    zachlindblad

    Joined:
    Sep 29, 2016
    Posts:
    39
    Ah ok, figured it out, I think the error is just strangely worded which was confusing.
    "Asset exists with main Type=<TYPE_X>, which is not assignable from the requested Type=<TYPE_X>"
    Implied to me that the asset was registered with addressables, but was unable to cast from some reason (Asset exists sure sounds like the asset exists), but the function throws this error if it's unable to find the asset as well. Double checking and rebuilding my addressables database fixed the issue!
     
  6. UnityDEVDEP

    UnityDEVDEP

    Joined:
    Feb 16, 2022
    Posts:
    3
    ok. it was very strange, but when I put Asset Provider in Assets from Bundles Provider, everything worked