Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't assign ScriptableObject in inspector

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 enter image description here
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: enter image description here 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.

like image 702
Alex Avatar asked Nov 21 '22 16:11

Alex


1 Answers

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.

like image 50
Timbermar Avatar answered Dec 30 '22 04:12

Timbermar