Why when using menuitem attribute in editor script it's not showing the new option item when doing right click mouse on gameobject in the hierarchy?

Viewed 11
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;

public class InteractableItemEditor : Editor
{
    [MenuItem("InteractableItem/Make InteractableItem", false, 11)]
    private static void InteractableItem()
    {
        foreach (GameObject o in Selection.gameObjects)
        {
            var g = o.GetComponent<InteractableItem>();
            if (!g)
            {
                o.AddComponent<InteractableItem>();
                o.tag = "Interactable Item";
            }
        }
    }
}

The script is in the Editor folder under the Assets.

I tried to change from MenuItem to ContextMenu but still it's now showing the "InteractableItem/Make InteractableItem" when making right click with the mouse on gameobject in the heirarchy.

1 Answers

Solution is to change the parent menu name to GameObject :

Instead this :

[MenuItem("InteractableItem/Make InteractableItem", false, 11)]

To this :

[MenuItem("GameObject/Make InteractableItem", false, 11)]
Related