Menu does not show up in UNity Editor

This is my code:

using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
using UnityEngine.UIElements;
using UnityEditor.UIElements;

public class TaskListEditor : EditorWindow
{
    VisualElement container;

    public const string path = "Assets/TaskList/Editor/EditorWindow/";

    [MenuItem("Nathan/Task List")]
    public void ShowWindow()
    {
        TaskListEditor window = GetWindow<TaskListEditor>();
        window.titleContent = new GUIContent("Task List");
    }

    public void CreateGUI()
    {
        container = rootVisualElement;
        VisualTreeAsset original = AssetDatabase.LoadAssetAtPath<VisualTreeAsset>(path + "TaskListEditor.uxml");
        container.Add(original.Instantiate());

        StyleSheet styleSheet = AssetDatabase.LoadAssetAtPath<StyleSheet>(path + "TaskListEditor.uss");
        container.styleSheets.Add(styleSheet);
    }
}

Are you getting any errors in the inspector?

Most commonly, the issue is a misspelling of the path, or an otherwise incorrect path.

I am not getting any errors, I will include a picture of the path so that you can confirm.

path

To clarify: Are you getting the menu item at the top of Unity
image

If so, when you click on it, does a window open?

If so, is the window blank?

I am not getting the menu item at the top

This method has to be static

    [MenuItem("Nathan/Task List")]
    public static void ShowWindow()
    {
        TaskListEditor window = GetWindow<TaskListEditor>();
        window.titleContent = new GUIContent("Task List");
    }

From the documentation:

@bixarrio thank you! That worked, at first, I tried to make the class static but then my whole script became full of errors but now I know I can also just make 1 method static. It now works flawlessly.

@Brian_Trotter also thanks for helping debug my problem

I can’t believe I missed that.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms