Skip to content

Instantly share code, notes, and snippets.

@mrcarriere
Last active October 11, 2018 16:42
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mrcarriere/8021e4b6adef8551a42bc6b6cc547dd2 to your computer and use it in GitHub Desktop.
Save mrcarriere/8021e4b6adef8551a42bc6b6cc547dd2 to your computer and use it in GitHub Desktop.
Force Unity to stop playing if you have edited a source file. Helps avoid some editor crashes and false positives / error spam. To use, drop this script in an "Editor" folder in your project.
using UnityEditor;
[InitializeOnLoad]
public class StopPlayingOnRecompile
{
static StopPlayingOnRecompile()
{
AssemblyReloadEvents.beforeAssemblyReload += () =>
{
if (EditorApplication.isPlaying)
{
EditorApplication.isPlaying = false;
}
};
AssemblyReloadEvents.afterAssemblyReload += () =>
{
if (EditorApplication.isPlaying)
{
EditorApplication.isPlaying = false;
}
};
EditorApplication.update += () =>
{
if (EditorApplication.isCompiling && EditorApplication.isPlaying)
{
EditorApplication.isPlaying = false;
}
};
}
}
@mrcarriere
Copy link
Author

This current version was updated to work with Unity 2017+

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment