Search Unity

  1. We are migrating the Unity Forums to Unity Discussions. On July 12, the Unity Forums will become read-only.

    Please, do not make any changes to your username or email addresses at id.unity.com during this transition time.

    It's still possible to reply to existing private message conversations during the migration, but any new replies you post will be missing after the main migration is complete. We'll do our best to migrate these messages in a follow-up step.

    On July 15, Unity Discussions will become read-only until July 18, when the new design and the migrated forum contents will go live.


    Read our full announcement for more information and let us know if you have any questions.

MenuItem priority hidden feature

Discussion in 'Documentation' started by Baste, Jun 1, 2016.

  1. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    6,371
    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:

    Code (csharp):
    1. using UnityEngine;
    2. using UnityEditor;
    3.  
    4. public class TEST : MonoBehaviour {
    5.  
    6.     [MenuItem("TEST/1", false, 1)]
    7.     public static void TEST1() {
    8.        
    9.     }
    10.  
    11.     [MenuItem("TEST/11", false, 11)]
    12.     public static void TEST11() {
    13.  
    14.     }
    15.  
    16.     [MenuItem("TEST/12", false, 12)]
    17.     public static void TEST12() {
    18.        
    19.     }
    20. }
    Gives this result:
    11112.png

    While this code:

    Code (csharp):
    1. using UnityEngine;
    2. using UnityEditor;
    3.  
    4. public class TEST : MonoBehaviour {
    5.  
    6.     [MenuItem("TEST/1", false, 1)]
    7.     public static void TEST1() {
    8.        
    9.     }
    10.  
    11.     [MenuItem("TEST/12", false, 12)]
    12.     public static void TEST12() {
    13.        
    14.     }
    15. }
    Gives this result:

    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?
     
    TimGS and Pulas like this.
  2. Alex_May

    Alex_May

    Joined:
    Dec 29, 2013
    Posts:
    198
    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.