Reputation: 1232
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.
Upvotes: 5
Views: 7908
Reputation: 137
That's because you did not add[System.Serializable] at the Buff:ScriptableObject class, so all your "buff" is not serializable, and Unity Editor can't read c# directly, it can only read c# that are serialized.
Upvotes: 1
Reputation: 109
create asset with specific file extension inside custom inspector using EditorGUILayout.ObjectField; DefaultAsset; Open/Save dialog detail video how do it
Upvotes: 1
Reputation: 414
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.
Upvotes: 1