- Home /
How to reference variable in ScriptableObject(.asset files)?
So basically I went out of the way to make a .asset file following http://wiki.unity3d.com/index.php?title=CreateScriptableObjectAsset
My issue now is I have no idea how to go about referencing the serialized code attached to said asset.
using UnityEngine; using System.Collections; using UnityEditor; using System;
[Serializable] public class BallStorage : ScriptableObject {
[SerializeField]
Sprite ballSprite;
[SerializeField]
int derpderpderpyderp;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
}
This is the code attached. I simple want to reference the sprite. I assume it's using resources.load, anyone have any experience in this?
Answer by MikeNewall · May 12, 2014 at 11:10 AM
Resources.Load will work.
BallStorage storage = Resources.Load<BallStorage>("BallStorage");
storge.ballSprite = blah;
You could also have a public variable exposed of the same type as your scriptable object in the inspector to drag your asset onto
The same can be done with ScriptableObject.CreateInstance()??
I can't manage to make it work with with CreateInstance. As i can see it load $$anonymous$$e script, not the assets, so most of the attributes are still blank.
Your answer
Follow this Question
Related Questions
Importing and using custom assets 0 Answers
Create Unity Parameter Asset? Uhhh i think? 1 Answer
Nested ScriptableObject assets? 1 Answer
Is there a message to be listen to when editor enter play mode? 2 Answers
[Solved]Why doesn't my ScriptableObject based asset save using a custom inspector ? 1 Answer