Creating vars in editor


I want to write my own custom editor for a skilltree system, and want to add and remove variables with a add button, but don’t know how to do this.

How do I create variables in the Inspector/editor for my script.

C# please,


Those variables shouldn’t reside on your custom editors but on your targets.

Supposing you have:

public List<Skill> skills;


public class Skill {
    string name;
    int modifier;

And, using SerializedObject and SerializedProperty APIs, you can modify and show your serialized data. Fast example:

serializedObject.Update ();
SerializedProperty skillsProp = serializedObject.FindProperty ("skills");
EditorGUILayout.PropertyField (skillsProp); // this will show default inspector for your custom class.. you'll have to iterate yourself to create your custom layout
skillsProp.InsertElementAtIndex (skillsProp.arraySize); // do this when you click your Add button
serializedObject.ApplyModifiedProperties (); // remember to apply those changes!