Hi there, I need a little more info than I find in: http://unity3d.com/support/documentation/ScriptReference/ScriptableObject.html I noticed that GUISkin is a scriptable object, so I thought maybe I could use ScriptableObject to create assets that exist in the project view, of which the properties can changed there and taht can then be dragged on the relevant properties in scripts that use this (just like it's done with the GUISkin). Now the magical question is: If that's possible, how do I get instances of my ScriptableObjects into the project? ;-) Or is this not what ScriptableObjects are meant to be used for? Then, what is it? Any info will be greatly appreciated... Sunny regards, Jashan
Yep, that's how the GUISkin asset works basically. If you want to create an asset _file_ that is saved to the project directory like GUISkin is, and you don't just want to just use it at runtime (CreateInstance(...), etc), you create an Editor script to create your asset, and hook it into the menu as you do with any Editor script (MenuItem attribute). The rest is using some undocumented stuff. It's a *use at your own risk* thing, because this stuff isn't officially supported yet, but it's in there and usable. Just don't yell at UT if it does something goofy or blows up your machine. ;-) Here is what the editor script would look like basically: Code (csharp): using UnityEngine; using UnityEditor; using System; public class MyAssetEditor { [MenuItem("Assets/Create/MyAsset")] public static void CreateMyAsset() { MyAsset asset = new MyAsset(); //scriptable object AssetUtility.CreateAsset(asset, "New MyAsset"); AssetUtility.SaveAsset(asset); EditorUtility.FocusProjectView(); Selection.activeObject = asset; } } Took a while to figure out. As I said, use at your own risk. ;-) All this being said, unless you really really need to do it this way, it would probably best to just use Prefabs for your "asset" objects. -Jeremy
Hi Jeremy, thanks - that does it for me I'm using this to store metadata for my levels that is really "global in nature". So, game objects and prefabs would really be kind of overkill for this, it's "above scene level in project level", so to say. What I have now is ten assets based on my ScriptableObject "LevelData" that contain the relevant meta-information (stuff like filename, human readable name, description and stuff like that). Which is very nice because I can change this in the editor while play-testing. Also, I get very nice "source-control" through the Asset Server ;-) The only thing I can see I need to be careful with: There's a few properties I change during runtime, so these get permanently changed in the LevelData objects. Not a big deal in my case, but something one sure needs to be aware of... Very nice! And of course: I hope this will soon be "officially supported" (actually, that little Editor script would really be nice in the ScriptableObject doc file). Sunny regards, Jashan
UT does some sort of voodoo to give GUISkin an icon, and extention other than asset, but I couldn't figure out how. This is close enough without the extension as long as you use good names for the different asset files. -Jeremy
Aside from moving the braces up to the beginning of the line where they belong :wink: - this is a one stop fix. Thanks!
i am new to unity i have to implement scriptable object in my project the above is the editor code how to write the class that inherits from scriptable object Any help will be appreciated Thanks
I know this thread is very old, however it popped up when i searched for ScriptableObjects and so others may find this useful: I've put together a helper editor extension that allows you to create a ScriptableObject and save it in the project. Unfortunately, Unity doesn't provide the option to create these types of objects from the editor, and so you have to code that solution yourself... Here's a link to the github repository where i posted my helper code: https://github.com/liortal53/ScriptableObjectFactory I also posted about it in my blog: http://www.tallior.com/2014/08/06/unity-scriptableobject-factory/ Hope this helps others!