- Home /
Unity 5 - ExitApplication(); causes Crash
Is Unity 5 not compatible with this code?
ExitApplication();
When launched within Editor or game app, both crash.
2 other ways I found that also quits the app are;
Application.Quit();
and
if (!Application.isEditor) System.Diagnostics.Process.GetCurrentProcess().Kill();
What is the difference between Exit and Quit?
It Exits the application, code seems not to work anymore.
I got the code from here, it was an answer where no one had problems with. Apparently it does have a Unity API since no one complained and also had thumbs up.
http://answers.unity3d.com/questions/780359/button-on-click.html
You probably shouldn't argue whether something is in the API if you don't know what you're doing in the first place. It crashes because the sample function provided in the answer you referenced calls itself infinitely and does nothing else. That answer wasn't aimed at how to quit the application, but how to handle button OnClick events. Granted, I guess it technically does close the app eventually.
Answer by Xarbrough · Nov 03, 2015 at 11:44 PM
The correct way to exit a Unity application is
Application.Quit()
Your third option using .NET is not what you want. Kill() is like opening Task Manager and killing a frozen process. You need to go the Unity built-in route, so that it cleanly exits and frees up memory.