Collapse stuff in Inspector


I have this camera and it has one script that handles a lot of stuff, like textures, displays, spawning items e.t.c. So what I need is to collapse stuff, like when you do for example AudioClip but instead it like makes a folder for it and I can access it like normal inside the script.

Is this possible to do, and if so, please tell me!


Yes, creating a CustomEditor for your class is probably the best way to get it to look the way you want. However if you just want to quickly “group” certain things you can simply create a serializable “data class” that contains your fields.

public enum EPlayMode { FirstOnly, Sequencial, Random }

public class AudioItem
    public float volume;
    public EPlayMode mode = EPlayMode.Random;
    public AudioClip[] clips;
    private int m_Next;
    public AudioClip Get()
        switch (mode)
            case EPlayMode.FirstOnly: return clips[0];
            case EPlayMode.Sequencial: {m_Next = m_Next % clips.Length; return clips[m_Next];}
            case EPlayMode.Random: return clips[Random.Range(0, clips.Length)];

public class AudioDefinitions
    public AudioItem jumpSound;
    public AudioItem walkSound;
    public AudioItem shootSound;

public class SomeMonoBehaviour : MonoBehaviour
    public AudioDefinitions audioClips;

So here we define an AudioClip array for each kind of sound we may need in the game. The “AudioItem” class holds this array along with some settings for one specific audio type. “AudioDefinitions” just groups all the different types of sounds we need into one class. Finally in the actual inspector we can collapse every “class” into a single item. Of course accessing a specific sound will become a bit more complicated. In this case to get a random jump sound you would have to do:

AudioClip clip = audioClips.jumpSound.Get();

Keep in mind that this is just an example. How you actually want to group your stuff highly depends on what kind of information you have. Note that you can also have arrays / Lists or serializable classes. If the class has a string field as first variable, it will show that string instead of “Element0”, “Element1”, … which is quite nice if you want to dynamically edit this information.

Unity actually did something like this in the old CharacterMotor script (found somewhere on github).

Yes, it is possible. You would have to do a CustomEditor for it. See docs.