- Home /
Save public List contents of monobehaviour object edited through custom editor tool
hey guys, I am trying to create an editor tool to help me populate the public List of a monobehaviour script attached to a gameobject. I have not extended the editor before, and so i dont know whats possible/isn't possible and have come here to ask whether or not what i am trying to do is feasible, or for a push in the right direction if it isn't! I'll start with a simple example, (this is essentially what I am trying to achieve with my tool except my tool will be used for another purpose)
Lets say I have a public member on one of my monobehaviour objects: public List listOfSomeData;
SomeData is a struct of data:
public struct SomeData
{
public string name;
public int age;
}
Now naturally, I can't edit a List in the editor without extending the editor. Would it be possible at all to do the following:
Attach the monobehaviour script to an object, and populate that objects listOfSomeData through a custom editor tool inside the editor.
'Save' this data by making the object with the attached script a prefab? (so that each instantiated object also contains the same value's for listOfSomeData that I specified earlier.)
Not asking for anyone to do it for me, I am just asking whether it is possible and a nudge in the right direction! :)
Answer by Bunny83 · Aug 15, 2012 at 10:11 AM
Structs can't be serialized by Unity. Just use a class instead. Due to the serializer, it almost behaves like a struct.
Don't forget to add the System.Serializable attribute
[System.Serializable]
public class SomeData
{
public string name;
public int age;
}
This should naturally be editable in the inspector.
Your answer
