• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
5
Question by ProtoTerminator · Dec 10, 2016 at 10:05 AM · compilingmenuitemcheckbox

MenuItem checkboxes disappearing on compile

Whenever my scripts get compiled (any time I make any changes) all of my custom menu items with checks get turned off. I tried updating them in a static constructor, but that never gets called. How can I get them to remain as they are?

 public const string clientMenu = "Build/Client";
 public const string serverMenu = "Build/Server";
 
 static BuildEditor()
 {
     EditorApplication.delayCall += Update;
 }
 static void Update()
 {
     foreach (BuildTargetGroup buildTarget in System.Enum.GetValues(typeof(BuildTargetGroup)))
     {
         if (buildTarget == 0 || buildTarget == (BuildTargetGroup)5 || buildTarget == (BuildTargetGroup)6 || buildTarget == (BuildTargetGroup)15 || buildTarget == (BuildTargetGroup)16)
         {
             continue;
         }
         if (PlayerSettings.GetScriptingDefineSymbolsForGroup(buildTarget).Contains("SERVER"))
         {
             Debug.Log("is server");
             Menu.SetChecked(serverMenu, true);
             Menu.SetChecked(clientMenu, false);
             break;
         }
         else
         {
             Debug.Log("is client");
             Menu.SetChecked(serverMenu, false);
             Menu.SetChecked(clientMenu, true);
             break;
         }
     }
 }
 
 [MenuItem(serverMenu)]
 public static void ChangeToServer()
 {
     if (Menu.GetChecked(serverMenu))
     {
         return;
     }
     Menu.SetChecked(serverMenu, true);
     Menu.SetChecked(clientMenu, false);
     foreach (BuildTargetGroup buildTarget in System.Enum.GetValues(typeof(BuildTargetGroup)))
     {
         if (buildTarget == 0 || buildTarget == (BuildTargetGroup)5 || buildTarget == (BuildTargetGroup)6 || buildTarget == (BuildTargetGroup)15 || buildTarget == (BuildTargetGroup)16)
         {
             continue;
         }
         PlayerSettings.SetScriptingDefineSymbolsForGroup(buildTarget, PlayerSettings.GetScriptingDefineSymbolsForGroup(buildTarget).Replace("SERVER", string.Empty) + ";SERVER");
     }
 }
 
 [MenuItem(clientMenu)]
 public static void ChangeToClient()
 {
     if (Menu.GetChecked(clientMenu))
     {
         return;
     }
     Menu.SetChecked(serverMenu, false);
     Menu.SetChecked(clientMenu, true);
     foreach (BuildTargetGroup buildTarget in System.Enum.GetValues(typeof(BuildTargetGroup)))
     {
         if (buildTarget == 0 || buildTarget == (BuildTargetGroup)5 || buildTarget == (BuildTargetGroup)6 || buildTarget == (BuildTargetGroup)15 || buildTarget == (BuildTargetGroup)16)
         {
             continue;
         }
         PlayerSettings.SetScriptingDefineSymbolsForGroup(buildTarget, PlayerSettings.GetScriptingDefineSymbolsForGroup(buildTarget).Replace("SERVER", string.Empty));
     }
 }
Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image KevinW · Jan 18, 2017 at 11:14 AM 0
Share

Any response on this? I'm seeing this as well, but I have confirmed it is just a visual issue with the checkmark. The state of the menu item and whatever data backing it are still "true" for checked items when the checkmark disappears during building. I even tried calling Menu.SetChecked again after building completed, but it still didn't show back up.

avatar image LukeDawn · May 23, 2017 at 01:24 PM 0
Share

Any news on this. I have exactly the same issue. On rebuild all of the menu checkboxes disappear.

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by ExcellencyHong · Nov 06, 2017 at 01:17 PM

well... i found the way for this case.

if you save a boolean flag about the checked state of the menu item(ex. EditorPref.SetInt()...etc), you can call a method before selecting the parent menuItem(ex. Build as your case).

in order to this way, you should make a method with the MenuItem attribute that the isValidateFunction property is true.

this validate function should be always return true. and you can write the code that load the flag saved and set Menu.SetChecked() to the flag saved;

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

62 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Menu Items as checkboxes/radio buttons 4 Answers

(Editor) How to add Checkmarks to MenuItems 4 Answers

The type or namespace 'var' could not be found (in C#) 7 Answers

Problem adding script to GUI Texture 1 Answer

Using Pragma to slit app in two 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges