ScriptChangesWhilePlaying option "Stop Playing and Recompile" not working as expected

I’ve set my ScriptChangesWhilePlaying option to Stop Playing And Recompile, but if I play my project and make script changes and then tab back to Unity, I get a certain amount of recompiling before it shuts down and OnEnable and Update methods run and throw errors because of things that have been partially cleaned up.

Is this feature broken, or does it just not work as I expect it to? I would expect that unity stops playing completely before recompiling happens.

It’s possible for OnEnable to occur if you accidentally create objects during destruction.

I’d recommend having a singleton like this:

public class ShutdownSingleton : MonoBehaviour
    public static bool s_IsShuttingDown = false;

    void OnApplicationQuit()
        s_IsShuttingDown = true;

And check ShutdownSingleton.s_IsShuttingDown in your OnDestroy and OnDisable methods.