Search Unity

Loading ScriptableObjects?

Discussion in 'Addressables' started by LlamaFarmer42, Jan 31, 2019.

  1. LlamaFarmer42

    LlamaFarmer42

    Joined:
    Jul 19, 2013
    Posts:
    9
    I'm using instances of a ScriptableObject called ItemRef to hold an item's name, and reference its prefab and its inventory prefab.

    I'm trying to load them using Addressables, labelled as "ItemRef". I'm using the code below, but it's not returning the the actual assets. It's returning a list of nulls of the right length, so it's finding the label entries but not getting the actual objects back.


    public class ItemRef : ScriptableObject { ... }

    public class ItemRefLoader
    {
    ...

    public void Load()
    {
    Addressables.LoadAssets<ItemRef>("ItemRef", null).Completed += OnItemsLoaded;
    }

    private void OnItemsLoaded (IAsyncOperation<IList<ItemRef>> op)
    {
    items = new List<ItemRef>(op.Result);
    // op.Result = [null, null, null, null]
    }
    }


    Can you load ScriptableObjects directly?

    I assumed it would be the same as the examples for loading a Material, but swapping the type. I've tried using ScriptableObject as the type, but it had the same result of a list of nulls.
     
    mandisaw likes this.
  2. MNNoxMortem

    MNNoxMortem

    Joined:
    Sep 11, 2016
    Posts:
    723
    @MaxBrowser yes you can. See the log and check if there are any deserialization problems. Currently in our WebGL builds we are running into some problems but I have done so successfully before (0.5.3, Unity 2018.3.2f1, new build player content after a change -> updates are not always detected to scriptable objects)
     
  3. unity_bill

    unity_bill

    Joined:
    Apr 11, 2017
    Posts:
    1,053
    Please try what @MNNoxMortem suggests, and if the problem persists, create a Unity bug report with a sample project.