- Home /
How set order in [MenuItem] attribute like in [CreateAssetMenu] attribute?
So with:
[CreateAssetMenu(fileName = "Surface_DB", menuName = "Database/Surface_Database", order = 1)]
i can set order in menu, but i switch to editor script because i can do more then just create new asset in root folder and now i must use:
[MenuItem("Assets/Create/Database/Surface_Database")]
there no parameter order, i can't use [CreateAssetMenu] attribute in editor script but [MenuItem] not have parameter order.
How i can add order to editor script or alernatives to [MenuItem] attribute in editor script?
Answer by LithiumBeach · Jul 14, 2018 at 06:39 PM
order = x does work, it's just tedious to find the correct value.
order = -1 will put your MenuItem at the very top of the Asets/Create menu.
order = ~500+ will put it at the bottom.
I ended up using order = 281 to put my MenuItem in it's own separator group, in between AudioMixer and Material. It's very trial and error unless you can find where Unity defines these.
Note: To actually update the order, you'll need to change it in code, compile, THEN close unity. Then reopen unity to see where it landed. Not the most ideal solution, but it worked for me!
Answer by Bunny83 · Jul 14, 2018 at 07:19 PM
The MenuItem attribute does have an order, it's just not called order but priority ^^. Just have a look at the constructor. Make sure you read the note about the priority at the end. When you have a difference of 11 or greater between two items Unity will insert a divider in the menu. Also keep in mind that you can create sub menus which is the usual way to logically group several menus.
Your answer
Follow this Question
Related Questions
Get Current Project Window Folder 2 Answers
Editor scripting - How to show the Assets menu as a context menu 1 Answer
When looping through assetbundle assetdatabase how do you reference a material object 0 Answers
A bug with "creating assets" 0 Answers
Can imported assets be automatically renamed by script? 0 Answers