Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • 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 $$anonymous$$enu.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.

Follow this Question

Answers Answers and Comments

60 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

Related Questions

(Editor) How to add Checkmarks to MenuItems 4 Answers

Menu Items as checkboxes/radio buttons 4 Answers

Error Building Player using Strip Assemblies 2 Answers

XCode Errors: "_AVCaptureSession" - Unity 3.5 compile problems? 2 Answers

Error:Windows-1252' not supported 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges