Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

1.1.10 Loading a Scriptable Object

Discussion in 'Addressables' started by Ferazel, Sep 4, 2019.

  1. Ferazel

    Ferazel

    Joined:
    Apr 18, 2010
    Posts:
    517
    I'm doing some tests with the 1.1.10 version of Addressables with Unity 2018.4.4.

    I'm trying to load a scriptable object from the addressable system and am getting a rather obtuse error that I'm not quite understanding that I'm wonder if someone could shed some light on. I've been able to load the standard asset reference types (Textures, Sprites, etc.).

    Code (CSharp):
    1. [CreateAssetMenu(fileName = "DataObject.asset", menuName = "MyMenu/TestDataObject")]
    2. public class DataScriptableObject : ScriptableObject
    3. {
    4.     [Serializable]
    5.     public class AssetReferenceDataScriptableObject : AssetReferenceT<DataScriptableObject>
    6.     {
    7.         public AssetReferenceDataScriptableObject(string guid) : base(guid) { }
    8.     }
    9.    
    10.     public string someStringData;
    11.     public int someIntData;
    12. }
    Then I'm setting up a monobehavior with an addressable asset

    Code (CSharp):
    1. public class CustomizationController : MonoBehaviour
    2. {
    3.     public CustomizationList.AssetReferenceCustomizationList optionsAddressable;
    4.    
    5.     void Start()
    6.     {
    7.         dataAddressable.LoadAssetAsync().Completed += op =>
    8.         {
    9.             DataScriptableObject loadedObj = op.Result;
    10.             Debug.LogFormat("LoadedDataObject: {0} String: {1} Number: {2}", loadedObj, loadedObj.someStringData, loadedObj.someIntData);
    11.         };
    12.     }
    13. }
    14.  
    Am I missing something obvious about how to use the API? This style of code works fine for the texture assets is this a limitation with scriptable data objects in the addressable system?

    I receive the following errors.
    Exception encountered in operation Resource<DataScriptableObject>(DataObject.asset): Unknown error in AsyncOperation
    UnityEngine.AsyncOperation:InvokeCompletionEvent()

    Exception encountered in operation UnityEngine.AddressableAssets.Initialization.InitializationOperation, result='', status='Succeeded' - Chain<DataScriptableObject,IResourceLocator>: ChainOperation of Type: DataScriptableObject failed because dependent operation failed
    Unknown error in AsyncOperation
    UnityEngine.ResourceManagement.ChainOperation`2:OnWrappedCompleted(AsyncOperationHandle`1)
    DelegateList`1:Invoke(AsyncOperationHandle`1) (at Library/PackageCache/com.unity.addressables@1.1.10/Runtime/ResourceManager/Util/DelegateList.cs:69)
    UnityEngine.ResourceManagement.ResourceManager:Update(Single)
    MonoBehaviourCallbackHooks:Update() (at Library/PackageCache/com.unity.addressables@1.1.10/Runtime/ResourceManager/Util/MonoBehaviourCallbackHooks.cs:19)

    NullReferenceException: Object reference not set to an instance of an object
    CustomizationController+<>c.<Start>b__8_0 (UnityEngine.ResourceManagement.AsyncOperations.AsyncOperationHandle`1[TObject] op) (at Assets/Scripts/CustomizationController.cs:28)
    DelegateList`1[T].Invoke (T res) (at Library/PackageCache/com.unity.addressables@1.1.10/Runtime/ResourceManager/Util/DelegateList.cs:69)
    UnityEngine.Debug:LogException(Exception)
    DelegateList`1:Invoke(AsyncOperationHandle`1) (at Library/PackageCache/com.unity.addressables@1.1.10/Runtime/ResourceManager/Util/DelegateList.cs:73)
    UnityEngine.ResourceManagement.ResourceManager:Update(Single)
    MonoBehaviourCallbackHooks:Update() (at Library/PackageCache/com.unity.addressables@1.1.10/Runtime/ResourceManager/Util/MonoBehaviourCallbackHooks.cs:19)
     
  2. Ferazel

    Ferazel

    Joined:
    Apr 18, 2010
    Posts:
    517
    I upgraded to 1.22 and the problems remains. I submitted a bug report because I don't think I'm doing anything incorrectly (since it works for textures). If the addressable team could take a look at it and let me know if it is something wrong I'm doing or if the package has a problem I'd appreciate it. Thanks!

    Bug# 1183875