- Home /
Can I make a class editable in the inspector, without having to have a GameObject associated with it?
So I have a simple data class like this:
[System.Serializable]
public class Bow
{
[SerializeField]
public Sprite[] AnimationSprites;
}
[System.Serializable]
public class TestClass : MonoBehaviour
{
[SerializeField]
private List<Bow> BowSprites = new List<Bow>();
}
Which when put on some GameObject gives me this:
Now, I want to have a bunch of bows, with attributes n stuff yknow the usual.
So I have a few ways of doing this:
Making a GameObject that holds my data script and reference this everywhere I need it.
or
Making a static class and manually code in all the values.
But I dont like either of them. Doing it manually is too much for for lazy me, and having a data object just seems... inconvinient. Like I will always have this Object in my Hirarchy, begging to be replaced by something more intuitive.
So what I need help with:
Can I make a static class, whose Variables I can edit like in the picture above, without having this data Game Object ruining the perfect View of the mess I call a game?
Maybe something like a custom menu, where I can put all my data? Like the input menu, just for sprites and other variables? I just want to have it organized and easy to edit. Anyone know how or if I can archive this?
Answer by CodesCove · Jan 23, 2021 at 07:06 AM
This might help solving your issue (an probably many other issues :) :
Attach the list to a ScriptableObject not to a Monobehavior. From ScriptableObject (derived) class you can instantiate it as asset in edit mode and you can reference a ScriptableObject (asset) from any Scene component and make use of its data and classes. It also persists across scenes (since it's asset and not scene component). Takes a while to get familiar with but it's really worth it.
Check out these links:
https://docs.unity3d.com/Manual/class-ScriptableObject.html
https://learn.unity.com/tutorial/introduction-to-scriptable-objects
This is wonderful, exactly what I wanted! Thank you, you wonderful person!
Your answer
Follow this Question
Related Questions
Change the target of inspector from script 0 Answers
TexturePropertySingleLine in Editor class 0 Answers
Editor Script, Index Out of Range Exception after Play 1 Answer
Gizmos.DrawLine is dissapearing after returning to editor after Playing the scene 0 Answers
OnInspectorGUI changes reset when played in editor or building 2 Answers