Search Unity

Menu items disabled after playing in editor

Discussion in 'Editor & General Support' started by SagoRich, Nov 30, 2016.

  1. SagoRich

    SagoRich

    Joined:
    Jul 21, 2014
    Posts:
    15
    Unity 5.4.3, Mac OS X 10.11.6

    Often after playing in the editor, then stopping, many (seemingly random) menus items are disabled, e.g.:

    Screen Shot 2016-11-30 at 10.37.22 AM.png

    Sometimes it is different items.
    Sometimes they stay disabled until we give up and restart Unity, other times they 'just come back'. I don't think we have any control over those. Ideas?
     
    Last edited: Nov 30, 2016
  2. xeleh

    xeleh

    Joined:
    Jul 22, 2016
    Posts:
    302
    Same here, totally random and not alway after playing in the editor. I am also on OSX 10.11.6, but in my case I begun to notice this in Unity 5.5. It's interesting to know that you're suffering this in 5.4.3 because I never used that version. I switched directly from 5.4.0 to 5.5 and can confirm this never occurred in 5.4.0.
     
    Last edited: Apr 11, 2017
  3. xeleh

    xeleh

    Joined:
    Jul 22, 2016
    Posts:
    302
    I think I have found a way to make it come back. When the menu items got disabled, just select a GameObject, click on the Add Component button and click again or press escape.

    And this is the automated version of this fix covering two known cases (after playing and after compiling). Simply save this as DisabledMenusFixer.cs under an Editor folder:

    Code (CSharp):
    1. #if UNITY_5_4_3 || UNITY_5_5_OR_NEWER
    2. using UnityEngine;
    3. using UnityEditor;
    4. using UnityEditor.Callbacks;
    5.  
    6. namespace UnityFixes {
    7.  
    8. public class DisabledMenusFixer {
    9.  
    10. [InitializeOnLoadMethod]
    11. static void SetupCallback() {
    12.     EditorApplication.playmodeStateChanged -= PlayModeChanged;
    13.     EditorApplication.playmodeStateChanged += PlayModeChanged;
    14. }
    15.  
    16. static void PlayModeChanged() {
    17.     if (!EditorApplication.isPlaying) {
    18.         Fix();
    19.     }
    20. }
    21.  
    22. [DidReloadScripts]
    23. static void Fix() {
    24.     // Nothing inspected? try later
    25.     if (Selection.activeGameObject == null) {
    26.         EditorApplication.delayCall += Fix;
    27.         return;
    28.     }
    29.     // Do the trick
    30.     EditorApplication.ExecuteMenuItem("Component/Add...");
    31.     if (EditorWindow.focusedWindow != null) {
    32.         EditorWindow.focusedWindow.SendEvent(Event.KeyboardEvent("escape"));
    33.     }
    34. }
    35.  
    36. }
    37.  
    38. }
    39. #endif
     
    Last edited: Jan 6, 2017
  4. SagoRich

    SagoRich

    Joined:
    Jul 21, 2014
    Posts:
    15
    That "Add Component, click/escape" is what I discovered too, but the automation is nice; thanks.
     
  5. xeleh

    xeleh

    Joined:
    Jul 22, 2016
    Posts:
    302
    You're welcome. I have just added conditional compilation and a security check to prevent an error when no GameObject is selected, so the fix is applied only once is possible.
     
  6. crafTDev

    crafTDev

    Joined:
    Nov 5, 2008
    Posts:
    1,820
    Has Unity been alerted about this yet? It's constantly happening and I am shocked that they haven't fixed yet...it even crashes Unity when I try to open a menu...

    Your script works, but this is annoying to say the least.

    Thanks,
    jrDev
     
  7. xeleh

    xeleh

    Joined:
    Jul 22, 2016
    Posts:
    302
    I don't know if this has been already reported. I didn't report it because I don't know (yet) how to reproduce the issue in a consistent way. In my experience, a vague report is enough for the issue to be ignored.
     
  8. CorneliaXaos

    CorneliaXaos

    Joined:
    Mar 1, 2017
    Posts:
    7
    Hey _xeleh_. I was having the same problem so I'm glad I found an automation to fix the problem.. I also tweaked your code a bit so that it does the trick without delay. Enjoy! :D

    Code (CSharp):
    1.  
    2. #if UNITY_5_4_3 || UNITY_5_5_OR_NEWER
    3. using UnityEngine;
    4. using UnityEditor;
    5. using UnityEditor.Callbacks;
    6.  
    7. namespace UnityFixes
    8. {
    9.  
    10.     public class DisabledMenusFixer
    11.     {
    12.  
    13.         [InitializeOnLoadMethod]
    14.         static void SetupCallback ()
    15.         {
    16.             EditorApplication.playmodeStateChanged -= PlayModeChanged;
    17.             EditorApplication.playmodeStateChanged += PlayModeChanged;
    18.         }
    19.  
    20.         static void PlayModeChanged ()
    21.         {
    22.             if (!EditorApplication.isPlaying) {
    23.                 Fix ();
    24.             }
    25.         }
    26.  
    27.         [DidReloadScripts]
    28.         static void Fix ()
    29.         {
    30.             GameObject oldSelection = Selection.activeGameObject;
    31.             Selection.activeGameObject = GameObject.CreatePrimitive (PrimitiveType.Cube);
    32.  
    33.             // Do the trick
    34.             EditorApplication.ExecuteMenuItem ("Component/Add...");
    35.             if (EditorWindow.focusedWindow != null) {
    36.                 EditorWindow.focusedWindow.SendEvent (Event.KeyboardEvent ("escape"));
    37.             }
    38.  
    39.             GameObject.DestroyImmediate (Selection.activeGameObject);
    40.             Selection.activeGameObject = oldSelection;
    41.         }
    42.  
    43.     }
    44.  
    45. }
    46. #endif
    47.  
    EDIT: I added something to track the old selection just in case the user had a previous selection... It could probably be optimized some more.. but it's really not gonna be THAT inefficient that it'd need it.
     
    Last edited: May 31, 2017
    crafTDev and xeleh like this.
  9. PeterB

    PeterB

    Joined:
    Nov 3, 2010
    Posts:
    366
    I have a similar problem: the entire File menu is disabled, as are some menu items on the Unity menu. However, your fix doesn't help. Any ideas?

    Screen Shot 2018-03-14 at 08.55.12.png Screen Shot 2018-03-14 at 08.55.20.png
     
  10. adslitw

    adslitw

    Joined:
    Aug 23, 2012
    Posts:
    275
    @PeterB I was having this problem too, are you using Unity Hub? Opening the Unity version I'm using directly solved the issue for me.
     
    PeterB likes this.
  11. PeterB

    PeterB

    Joined:
    Nov 3, 2010
    Posts:
    366
    Yes, I am using Unity Hub. I managed to solve it by reimporting the whole project. This has solved it temporarily before, but I shall check out your solution.
     
  12. PeterB

    PeterB

    Joined:
    Nov 3, 2010
    Posts:
    366
    @adslitw, you seem to be correct: rebuilding the project only fixes it temporarily. Opening the Unity version directly fixes it. Shame that Unity tests its own released software so sketchily before releasing.
     
  13. adslitw

    adslitw

    Joined:
    Aug 23, 2012
    Posts:
    275
    @PeterB I'm usually more than happy to jump on the 'dammit Unity sort your S*** out!' bandwagon, but as far as I'm aware Unity Hub isn't even in beta, it's just a preview! They probably deserve a bit of slack on that one. :)

    edit: looks like they are calling it a beta. But yeah, it's beta, so there are likely to be problems.
     
    afshinity and PeterB like this.
  14. PeterB

    PeterB

    Joined:
    Nov 3, 2010
    Posts:
    366
    Well, a beta which doesn't allow the project to be saved is more akin to an alpha than anything else. It's incredible that stuff like this seeps through time and time again. But I will file an error report, like a good paid Unity citizen and unpaid beta tester. ;)
     
  15. AbrahamDUnity

    AbrahamDUnity

    Unity Technologies

    Joined:
    Jun 28, 2017
    Posts:
    431
    Hello,

    Sorry to hear you are experiencing issues with the Hub. If you could describe the issue in a new thread in our forum and possibly give reproduction steps we will look into the issue and try to fix this.

    Best,
     
  16. PeterB

    PeterB

    Joined:
    Nov 3, 2010
    Posts:
    366
    @AbrahamDUnity: The case number is 1014167, in case you need to refer to it. I'll create a new thread for it.
     
  17. AbrahamDUnity

    AbrahamDUnity

    Unity Technologies

    Joined:
    Jun 28, 2017
    Posts:
    431
    Thank you @PeterB. The new thread would be preferable since this thread wasn't exactly related to your issue.
     
  18. AbrahamDUnity

    AbrahamDUnity

    Unity Technologies

    Joined:
    Jun 28, 2017
    Posts:
    431
    For anyone who wants to follow up on the Hub related issue please continue the conversation on this thread.

    Thanks