- Home /
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));
}
}
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.
Any news on this. I have exactly the same issue. On rebuild all of the menu checkboxes disappear.
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;