MenuItem has some pretty strange and archaic rules around their ordering and layout. It’s all built around the priority value of the menu item, but that system seems to have been thrown together a decade ago as a stopgap and then never touched again.
If you want to position an element next to a different one, you’ll need to give it a priority value that’s one more or less than that item. But there’s no way to figure out the priority value of builtin menu items other than trial and error! So if we want to be close to something related, we have to binary search our priority until we hit the correct spot.
You can also get vertical dividers between the elements. As an example, here’s a vertical divider between Package Manager and Asset Management in the window menu.

That shows up if the difference between the priority of different elements is larger than 10:
[MenuItem("Test/Item1", false, 0)]
public static void Foo() {}
[MenuItem("Test/Item2", false, 10)]
public static void Bar() {}
Gives

[MenuItem("Test/Item1", false, 0)]
public static void Foo() {}
[MenuItem("Test/Item2", false, 11)]
public static void Bar() {}
Gives:

That’s a) not written down and b) a really strange way to do things! It also means that if there are two things with a divider, but the difference between them is less than 22, then you can’t add a new item with dividers between them.
Finally, it’s really confusing how we position a category. The ID’s used are used to position things next to each other inside a category menu, but how is the category itself positioned? Hard to explain, so if you look here:

TextMeshPro is positioned over General, and under Text. But there’s no [MenuItem(“Window/TextMeshPro”)]! So I assume that the positioning of TextMeshPro here is based on the value of either the lowest or highest element that starts with Window/TextMeshPro, and then that’s compared to the same for things that are inside of General/ or Text/, but this is again not written down and also totally confusing.
So this system could really be improved! Some suggestions are:
- Make a static class or enum that lists all the ID’s that Unity uses internally, so we can access that to position ourselves next to elements.
- Write down all the rules for positioning
- Make dividers not be based on the numeric distance between elements, but instead have bools or enums or whatever on MenuItem that allows us to say things like “I want a divider below/above this element”
Knowing Unity, I assume that what’s happened here is that this whole thing has been known of as problems, and then you have tried to make a fancy, perfect system to replace it, and all of those have been to fancy and have failed. Any chance you’d (for once) go for an incremental improvement here?

