MenuItem priority

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.
8757955--1187020--upload_2023-1-26_10-20-52.png

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
8757955--1187026--upload_2023-1-26_10-26-55.png

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

Gives:
8757955--1187023--upload_2023-1-26_10-26-25.png

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:
8757955--1187032--upload_2023-1-26_10-34-15.png

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?

You’re absolutely right! Layout and order limiting rules are indeed the limiting factor to progress with this faster. As you correctly identified one of the limiter is priority number based order instead of groups (collections) or relations between items (e.g. “Paste” relates to “Copy”). Adding automatic separators feature every tenth item is sometimes good to have but sometimes very questionable.
To solve another question of current menu items priorities it is possible to enable it via editor preferences as pictured. When enabled, after reload it will display number value next to each menu item, hope it helps somebody to not get lost in this :slight_smile:

2 Likes

The menu display priority is Gone in 2021.3.36.

How can I order the items in a human way? I am getting lost and driving crazy trying to figure it.

Yeah I can’t find it in Unity 6 either :frowning:

I’m still seeing it in Unity 6:

1 Like

It appears to be missing in Unity 6.2.13f1 on mac as well…