So apparently i suck at listening at my university, because i can't figure this out, not even with google... How do you create a scriptable object in the editor? I have the project open, it looks like this:
Click the Create button as if you wanted to create a folder or C# script or anything.
Select the ScriptableObject from the popup menu.
Get this panel and finalize the object after selecting the script for it.
The problem is: i don't have the ScriptableObject button. I have a script that is a scriptable object (to make sure i even copied the one from the project of the university). I restarted Unity, i checked if there were any packages installed (there werent) and i googled quite a bit. But i just can't seem to get this working...
Is there anything i have to install or add first? Thanks in advance!
What are ScriptableObjects? ScriptableObject is a serializable Unity class that allows you to store large quantities of shared data independent from script instances. Using ScriptableObjects makes it easier to manage changes and debugging.
You need another script to add the button which will create an instance from that scriptable object. something like that
using UnityEngine;
using System.Collections;
using UnityEditor;
public class MakeScriptableObject {
[MenuItem("Assets/Create/My Scriptable Object")]
public static void CreateMyAsset()
{
MyScriptableObjectClass asset = ScriptableObject.CreateInstance<MyScriptableObjectClass>();
AssetDatabase.CreateAsset(asset, "Assets/NewScripableObject.asset");
AssetDatabase.SaveAssets();
EditorUtility.FocusProjectWindow();
Selection.activeObject = asset;
}
}
You can check this Introduction to Scriptable Objects tutorial on unity website.
I can't comment so just place it like answer: Don't forget to use UnityEditor.AssetDatabase.GenerateUniqueAssetPath coz simple AssetDatabase.CreateAsset can erase your data:
using UnityEngine;
using System.Collections;
using UnityEditor;
public class MakeScriptableObject
{
[MenuItem("Assets/Create/My Scriptable Object")]
public static void CreateMyAsset()
{
MyScriptableObjectClass asset = ScriptableObject.CreateInstance<MyScriptableObjectClass>();
string name = UnityEditor.AssetDatabase.GenerateUniqueAssetPath("Assets/NewScripableObject.asset");
AssetDatabase.CreateAsset(asset, name);
AssetDatabase.SaveAssets();
EditorUtility.FocusProjectWindow();
Selection.activeObject = asset;
}
}
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