MenuItem priority hidden feature

The MenuItem attribute has a priority argument, which defines the order in the submenu the menu item is placed in.

What’s not documented anywhere in the docs is that if the difference between two menu item’s priority is greater than 10, a line will be added.

This code:

using UnityEngine;
using UnityEditor;

public class TEST : MonoBehaviour {

    [MenuItem("TEST/1", false, 1)]
    public static void TEST1() {
       
    }

    [MenuItem("TEST/11", false, 11)]
    public static void TEST11() {

    }

    [MenuItem("TEST/12", false, 12)]
    public static void TEST12() {
       
    }
}

Gives this result:
2659190--187511--11112.png

While this code:

using UnityEngine;
using UnityEditor;

public class TEST : MonoBehaviour {

    [MenuItem("TEST/1", false, 1)]
    public static void TEST1() {
       
    }

    [MenuItem("TEST/12", false, 12)]
    public static void TEST12() {
       
    }
}

Gives this result:

2659190--187512--112.png

The behaviour with the dividing lines should be documented, and the order of the default elements of all the lists should be documented, so we can know where our menu items gets placed.

Information about what happens if two menu items have the same priority should also be included.

Finally; why is the variable namesd “priority”, when what the field defines is order?

2 Likes

That seems really arbitrary to me. Why not have a specific divider property? And this isn’t the only poorly-named property we have either (RectTransform.sizeDelta, I am looking at you).

Thanks for the report, I’ll add it to be documented.