I'm having trouble with assigning ScriptableObjects in inspector.
For example, I have this class:
using UnityEngine;
public class Buff : ScriptableObject {
public string buffName;
}
In one of the monobehavior-derived classes, I have a member like this:
public Buff testBuff;
In inspector I see the following, but I can't drag+drop script 'Buff' to this member
It works to drag+drop Buff as a new script, but I can't add it to 'Test Buff'.
What I tried instead of dragging+dropping is to simply create an instance of Buff like so:
public Buff testBuff = new Buff();
This worked: However I believe drag+drop should work as well, plus the above gives warning:
Buff must be instantiated using the ScriptableObject.CreateInstance method instead of new Buff.
UnityEngine.ScriptableObject:.ctor()
Buff:.ctor()
...
I'm using Unity "5.0.2f1 Personal", which is the latest version.
You need to create an asset file that uses your Scriptable Object as it's type. This can only be done with an editor script. There is a generic one on the wiki.
Essentially you just create a menu item for each Scriptable Object type you have, use the menu item to create assets of those types, and then modify the assets with the values you want them to have. It's important to remember that SCOs are to be used as templates, if you modify a SCO either in the editor or with code those changes will instantly take effect on all GameObjects and Components that reference the SCO.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With