The Quickest Guide to Quitting Games in Unity

Quit Games in Unity Like a Pro

Daniele Quero, PhD
Geek Culture

--

Objective: quit the game using code

To quit a game in Unity, a very simple method from the Unity Engine library comes to help.

But before using it, we have to know how it works and where it can work. The simple answer we are all looking for is:

it quits the game but works only in a real instance of the game running.

This means that using it while testing in the Unity Editor won’t have any effect. So this is how to overcome this:

With a preprocessor directive, we can check if the game is running in the editor… or not.

If we are in the editor, there is no game to quit and we just need to stop the “Playing Mode” of the Editor Application.

If we are not, meaning that the game is running for real, we can easily and naturally quit it. This applies to ALL platforms.

All it remains to do is call that Quit() method where needed (upon input or as a callback for…

--

--

Daniele Quero, PhD
Geek Culture

A professional developer with passion for game developing and skill-growing. A former Nuclear Physics Researcher who changed his life to pursue his dreams