Skip to content

Instantly share code, notes, and snippets.

@James-Frowen
Created February 15, 2021 21:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save James-Frowen/6b8d92e10df2488d903950db6e5780a2 to your computer and use it in GitHub Desktop.
Save James-Frowen/6b8d92e10df2488d903950db6e5780a2 to your computer and use it in GitHub Desktop.
Exits play more when scripts are recompiled
using UnityEditor;
using UnityEditor.Compilation;
using UnityEngine;
namespace JamesFrowen.EditorScripts.Compilation
{
/// <summary>
/// Stop the game the scripts are recomplied
/// </summary>
[InitializeOnLoad]
public static class ExitPlayModeOnCompile
{
static ExitPlayModeOnCompile()
{
#if UNITY_2019_1_OR_NEWER
CompilationPipeline.compilationStarted += CompilationPipeline_compilationStarted;
#else
CompilationPipeline.assemblyCompilationStarted += CompilationPipeline_compilationStarted;
#endif
}
/// <summary>
/// Stop playing before compile, this is useful for scripts that dont behave well with reloading
/// </summary>
/// <param name="obj"></param>
private static void CompilationPipeline_compilationStarted(object obj)
{
if (Application.isPlaying)
{
EditorApplication.isPlaying = false;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment