Skip to content

Instantly share code, notes, and snippets.

@SiarheiPilat
Created October 29, 2020 13:19
Show Gist options
  • Select an option

  • Save SiarheiPilat/b8950c09be0733db34e6f3bcf9d8a7a4 to your computer and use it in GitHub Desktop.

Select an option

Save SiarheiPilat/b8950c09be0733db34e6f3bcf9d8a7a4 to your computer and use it in GitHub Desktop.
How to disable a given MenuItem based on a certain condition using the isValidateFunction argument.
using UnityEditor;
public static class DisableMenuItem
{
[MenuItem("Examples/How to disable a custom menu item")]
static void DisableMenuItemExample(){ }
// Disable the menu item under a certain condition. This is where isValidateFunction comes in play, by the way.
[MenuItem("Examples/How to disable a custom menu item", true)]
static bool ValidateMenuItem(){ return Selection.activeGameObject != null; }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment