Organizing Components with AddComponentMenu in Unity

Organizing Components with AddComponentMenu in Unity

Steve Mcilwain's photo
Steve Mcilwain
·Aug 9, 2022·

1 min read

Subscribe to my newsletter and never miss my upcoming articles

Play this article

Inspector > Add Component

By default, when you create a new MonoBehaviour component, it is added to the menu under Scripts/{namespace}/{component} and gets jumbled in with a lot of other random stuff from packages you have imported.

Default Example

namespace PlayableDesign.ThriftShop
{
    public class CameraController : MonoBehaviour
    {
    }
}

Menu

image.png

image.png

Yuck!

AddComponentMenu

Instead, you can create a custom folder at the top level of the context menu in the editor using the AddComponentMenu attribute.

Better Example


[AddComponentMenu("Custom/" + nameof(CameraController))]
public class CameraController : MonoBehaviour
{

}

Menu

image.png

image.png

Best Example

Even better, I like to use dashes as the folder name so that my components are always on top.


[AddComponentMenu("-----/" + nameof(CameraController))]
public class CameraController : MonoBehaviour
{

}

Menu

image.png

Enjoy!

 
Share this