Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice

Crash Exiting Editor Play Mode with Custom PlayerLoop [Fix]

Discussion in '2018.1 Beta' started by S_Darkwell, May 1, 2018.

  1. S_Darkwell

    S_Darkwell

    Joined:
    Oct 20, 2013
    Posts:
    320
    Hello,

    Testing out custom PlayerLoop functionality, Unity would consistently crash when exiting play mode.

    Below is a fix I discovered, posted here to assist others suffering from the same issue.

    Code (CSharp):
    1. using UnityEditor;
    2.  
    3. [InitializeOnLoad]
    4. public static class EditorFixExitPlayModeCustomPlayerLoopCrash
    5. {
    6.     static EditorFixExitPlayModeCustomPlayerLoopCrash()
    7.     {
    8.         EditorApplication.playModeStateChanged += state => {
    9.             if (state == PlayModeStateChange.ExitingPlayMode)
    10.                 EditorApplication.isPaused = true;
    11.         };
    12.     }
    13. }
    Be well!
    - S.