Runtime Loading

A way to load exported .asset scriptableobject file into a scene on runtime is nothing different as any other things in Unity3D.

Let's consider you have a simple spreadsheet as shown as the below image:

And you've already exported it as .asset scriptableobject.

Things to do to load .asset scriptableobject is same as what for a prefab file.

First, create a new MonoBehaviour script file then declare PlayerItem class instance as public.

public class SimpleLoader : MonoBehaviour
    // You've already have PlayerItem class
    public PlayerItem playerItem;

    void Start ()
        // PlayearItem.dataArray array contains all exported data.
        // It will put out Value0 value, 0 onto the console.
        Debug.LogFormat("Value0: {0}", playerItem.dataArray[0].Value0);

Now, just drag .asset file and drop it into the Inspector view.

That's all what to load .asset file on runtime. Now start to play and the value of 'Valaue0' will be put in the console.

results matching ""

    No results matching ""