Search Unity

Question Scriptable Object inside an Addressable Folder causes Exception

Discussion in 'Editor & General Support' started by sirnic, Sep 14, 2021.

  1. sirnic

    sirnic

    Joined:
    Sep 7, 2017
    Posts:
    2
    I have an addressable folder with game data which I load on runtime. Everything works fine until I add a Scriptable Object inside that folder, then I get this Exception and the loading process fails:


    Exception thrown in DynamicInvoke: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.NullReferenceException: Object reference not set to an instance of an object
    .
    .
    last line:
    UnityEngine.ResourceManagement.Util.DelayedActionManager:LateUpdate () (at Library/PackageCache/com.unity.addressables@1.18.15/Runtime/ResourceManager/Util/DelayedActionManager.cs:159)


    The weird thing is when I delete the Scriptable Object and recreate it, it works for some time and then it randomly starts throwing the exception again.

    I'm loading the folder with:


    Code (CSharp):
    1. Addressables.LoadAssetAsync<UnityEngine.Object>(location);

    Tried various unity versions, without success. Any ideas how I can fix this or why it's not working?
     
  2. SxWx

    SxWx

    Joined:
    Apr 13, 2013
    Posts:
    3
    Faced with the same issue
    Roll back addressables to 1.17.17 (Unity 2021.1.21.f1) helped temporary, later new error appeared:

    Unable to load asset of type ... from location ...

    Updates:
    Probably issue appeared because I've called:
    GameObject.DestroyImmediate(Texture, true);

    when I've added check -> problem gone for now
     
    Last edited: Sep 24, 2021
  3. sirnic

    sirnic

    Joined:
    Sep 7, 2017
    Posts:
    2
    Found the issue:

    The problem was that the class name of the Scriptable Object was different from its file name.
    So apparently the SO lost the reference to the script after some time and couldn't recreate it because it couldn't find the file with the same name.

    Unity actually triggers a warning because of this, but unfortunately I didn't see it because I had warnings hidden.
     
  4. glenneroo

    glenneroo

    Joined:
    Oct 27, 2016
    Posts:
    231
    I'm getting this exception (1000x in < 1 second) suddenly after upgrading from 2020.3.22f1 to 25f1. If I downgrade back to .22 it's gone again. Rebuilding my Addressables doesn't help at all. No Scriptable Objects at all either.

    Using Addressables 1.18.19. Upgrading to 1.19.13 or 1.19.15 now I get different exceptions for all of my prefabs (which are also happening during DelayedActionManager.InternalLateUpdate line 159):
    Exception: Unable to load asset of type UnityEngine.GameObject from location Assets/AddressableData/Prefabs/Test.prefab.

    EDIT: Looks like there's an open bug report here: https://issuetracker.unity3d.com/is...ssets-have-labels-when-entering-the-play-mode
     
    Last edited: Jan 5, 2022
  5. SyedHussainAli

    SyedHussainAli

    Joined:
    Nov 16, 2022
    Posts:
    1
    Hi i am a new dev. i want to pass scriptable object through addressable but its giving me the errors
    i tried with two ways no luck.

    [Serializable]
    public class AssetReferenceScriptableObject : AssetReferenceT<TestScriptableObject>
    {
    public AssetReferenceScriptableObject(string guid) : base(guid) { }
    }


    [SerializeField]
    private AssetReferenceScriptableObject scriptableObject;


    1:

    //scriptableObject.LoadAsset<ScriptableObject>().Completed += (SOref) =>
    // {
    // Debug.Log("This Code is Working" + (TestScriptableObject)SOref.Result);
    // imageContainer.GetComponent<UITEST>().test = (TestScriptableObject)SOref.Result;
    // };
    2:
    if (scriptableObject.Asset != null && imageContainer.test==null)
    {
    imageContainer.test = scriptableObject.Asset as TestScriptableObject;
    }

    Kindly if anyone have any solution may be any blog, video or anything ,do share here
    Thanks in advance

    Error:

    UnityEngine.AddressableAssets.InvalidKeyException: Exception of type 'UnityEngine.AddressableAssets.InvalidKeyException' was thrown. No MergeMode is set to merge the multiple keys requested. Keys=, Type=TestScriptableObject
    UnityEngine.AddressableAssets.AssetReference:LoadAssetAsync<TestScriptableObject> ()
    AddressableManager:AddressableManager_Completed (UnityEngine.ResourceManagement.AsyncOperations.AsyncOperationHandle`1<UnityEngine.AddressableAssets.ResourceLocators.IResourceLocator>) (at Assets/AAAAA Addressables/Scripts/AddressableManager.cs:67)
    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)
    UnityEngine.ResourceManagement.ResourceManager:Update (single)