Skip to main content
Support
Search our knowledge base

How to stop automatic assembly compilation from script

Comments

3 comments

  • dirk

    This worked perfectly. Much appreciated.

    0
  • Morte

    FYI, since Unity 2017.2, these warnings for lines 21, 33 make the above editor script ineffective as-is:

    Assets/Editor/CompilerOptionsEditorScript.cs(33,27): warning CS0618: `UnityEditor.EditorApplication.playmodeStateChanged' is obsolete: `Use EditorApplication.playModeStateChanged and/or EditorApplication.pauseStateChanged'

    Assets/Editor/CompilerOptionsEditorScript.cs(33,27): warning CS0618: `UnityEditor.EditorApplication.playmodeStateChanged' is obsolete: `Use EditorApplication.playModeStateChanged and/or EditorApplication.pauseStateChanged'


    Per suggestion, fixing the capitalisation from

    playmodeStateChanged

    to

    playModeStateChanged

    https://docs.unity3d.com/2017.2/Documentation/ScriptReference/EditorApplication-playModeStateChanged.html

     
    gets a different new error:
    Assets/Editor/CompilerOptionsEditorScript.cs(33,27): error CS0123: A method or delegate `CompilerOptionsEditorScript.PlaymodeChanged()' parameters do not match delegate `System.Action<UnityEditor.PlayModeStateChange>(UnityEditor.PlayModeStateChange)' parameters

    which appears related to the issue noted here:

    https://github.com/dotBunny/VSCode/issues/162

    and as some current doc illustrates,

    https://docs.unity3d.com/ScriptReference/EditorApplication-playModeStateChanged.html

    The new function takes one parameter, so the delegate method in the above editor script needs to be updated with a valid matching parameter, e.g.
        static void PlaymodeChanged(PlayModeStateChange state)

    however the delegate method does not currently do anything with that state variable, and in some circumstances the following line:
    if( EditorApplication.isPlaying )
    can be replaced with something like:
    if (state==PlayModeStateChange.EnteredPlayMode)
    but it will probably work as-is.

    Refer to the doc on the exact meaning of those state enumerations:
    https://docs.unity3d.com/ScriptReference/PlayModeStateChange.html

    The old function name will work up to and including 2017.1
    https://docs.unity3d.com/2017.1/Documentation/ScriptReference/EditorApplication-playmodeStateChanged.html

    0
  • Ivan Zverev

    As of (at least, Unity doesn't pay me to QA) 2021.1.5f1, this no longer works (even with the proposed changes to get around the obsolete warnings). The if condition in OnEditorUpdate is never hit, even if you are in play mode and compiling. The isCompiling flag is never set to true before compilation is triggered and you start the dreaded null reference exception parade.

    I was able to get around this by just removing the isCompiling flag (you still get a short "is compiling" popup in unity, but it doesn't seem to go any further

    1

Please sign in to leave a comment.