1
\$\begingroup\$

I'm trying to get new items to appear in Unity's Assets→Create menu.

Screenshot of Assets menu in Unity editor

I'm defining these inside another project which is referenced as a package. The general goal here is to share my editor scripts a bit more easily than people having to import a package archive.

The setup is as follows:

  • Main project, HakanaiShaderCommonsExamples, references HakanaiShaderCommons as a package (currently by a local directory reference, actual production version references it by git URL, as seen here.)

    Screenshot of Packages section in Unity editor

  • In HakanaiShaderCommons/Scripts/Editor/CreationMenu.cs I have added my top-level static methods for the menu items:

    using UnityEngine;
    using UnityEditor;
    
    namespace HakanaiShaderCommons
    {
        public static class CreationMenu
        {
            [MenuItem("Assets/Create/Hakanai Shader/Raycast Shader", false, 100)]
            public static void CreateRaycastShader()
            {
            }
    
            [MenuItem("Assets/Create/Hakanai Shader/Raymarch Shader", false, 101)]
            public static void CreateRaymarchShader()
            {
            }
        }
    }
    
  • In HakanaiShaderCommons/Scripts/Editor/Unity.HakanaiShaderCommons.Editor.asmdef (which I learned I need only just today), I have:

    {
      "name": "Unity.HakanaiShaderCommons.Editor",
      "references": [
      ],
      "includePlatforms": [
        "Editor"
      ],
      "excludePlatforms": [],
      "allowUnsafeCode": false,
      "overrideReferences": false,
      "precompiledReferences": [],
      "autoReferenced": true,
      "defineConstraints": [],
      "versionDefines": [
      ],
      "noEngineReferences": false
    }
    

Back in Unity, my items don't appear in the menu. But I also get no errors to indicate what might have gone wrong.

If I compare what I'm doing to TextMeshPro, whose menu item is working, I can't figure out what's different about mine compared to theirs, other than their .asmdef file referring to their dependencies.

What is the trick here?

I know it is not:

  • The package name / namespace of my script, because TextMeshPro have TMPro as their namespace even though the assembly is named Unity.TextMeshPro.Editor.
\$\endgroup\$

0

You must log in to answer this question.

Browse other questions tagged .