Skip to content

Latest commit

 

History

History
37 lines (28 loc) · 659 Bytes

UNT0020.md

File metadata and controls

37 lines (28 loc) · 659 Bytes

UNT0020 MenuItem attribute used on non-static method

The MenuItem attribute turns any static function into a menu command. Only static functions can use the MenuItem attribute.

Examples of patterns that are flagged by this analyzer

using UnityEngine;
using UnityEditor;

class Camera : MonoBehaviour
{
    [MenuItem(""Name"")]
    private void Menu1()
    {
    }
}

Solution

Fix method signature:

using UnityEngine;
using UnityEditor;

class Camera : MonoBehaviour
{
    [MenuItem(""Name"")]
    private static void Menu1()
    {
    }
}

A code fix is offered for this diagnostic to automatically apply this change.