Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
17
Question by cgeopapa · Feb 11, 2015 at 05:40 PM · javascriptnotworking

Application.Quit not working?!

Hello, Weel I have this script:

 function Quit() {
 print("Unity, please Quit!!!");
 Application.Quit();
 }

But it is not working. I call the functioni from a UI button. It does prints the string, but it doesnt quit!

What is wrong???

Comment
Add comment · Show 4
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Malice983 · May 29, 2016 at 07:38 AM -1
Share

I do not see the year on any of these answers but the question was asked in 2015. It's 2016 now and I use 5.3.4, The Application.Quit function does not work . When you build and run from the internet or in system it does not make the game quit. Understood that in editor making the game quit would shut the editor down but when you build and run this function doe not really work as originally intended.

avatar image tanoshimi Malice983 · May 29, 2016 at 07:43 AM 0
Share

Please don't post an answer unless you're attempting to answer the question. Application.Quit works just fine and always has done to exit a standalone game... if it's not doing what you expected you need to show how you are calling it, and what you are trying to achieve.

avatar image Raresh Malice983 · May 29, 2016 at 09:35 AM 0
Share

Do not necro please.

avatar image AlucardJay Raresh · May 29, 2016 at 10:58 AM 1
Share

UA is not a forum, the concept of 'necro-ing' is not applicable.

5 Replies

· Add your reply
  • Sort: 
avatar image
33
Best Answer

Answer by ElMenduko · Feb 11, 2015 at 05:50 PM

Your game doesn't close when testing it in the editor (pressing the play button) because it would close unity... and that means loosing everything, having to open it again, etc.

To test it you should build and run your game:

Fast way: Files>Build and Run

Slower way: Files>Build settings... (Some settings that may be useful for you)

When you build it you need to create a folder where unity will put the .exe and the other files in. Then you can run it as a standalone program. (Assuming you build and run for the Windows Standalone)

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image AlucardJay · May 29, 2016 at 10:16 AM 0
Share

As stated in the Unity Scripting Reference : http://docs.unity3d.com/ScriptReference/Application.Quit.html

Quit is ignored in the editor or the web player.

avatar image
73

Answer by TBruce · Mar 18, 2016 at 08:38 PM

You need to quit the game differently if it is being run in the editor. This does not close the Unity editor if you are running the game within Unity it only closes the game.

 public void QuitGame()
 {
     // save any game data here
     #if UNITY_EDITOR
         // Application.Quit() does not work in the editor so
         // UnityEditor.EditorApplication.isPlaying need to be set to false to end the game
         UnityEditor.EditorApplication.isPlaying = false;
     #else
         Application.Quit();
     #endif
 }
Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Dev_S · Jul 27, 2019 at 08:56 PM 0
Share

Brilliant!

avatar image jgarbeidi · Jun 28, 2021 at 07:25 PM 0
Share

This is such a simple thing, but it seems like the kind of thing that will save so much time over the months anD years of development. Thank you for sharing this gem! <3

Edit: Typo.

avatar image
8

Answer by drod7425 · Feb 11, 2015 at 05:54 PM

If you are - in fact - trying to get the Unity editor to close from your UI, then here's the code to do it:

 function Quit(){
     EditorApplication.Exit(0);
 }

CAUTION: This will close your unity application and you will lose any unsaved data.

BONUS EDIT: If you just want to stop the application in the editor, you can use the following. Note that it will not work in your builds:

 function Quit(){
     EditorApplication.isPlaying = false;
 } 
Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image drod7425 · Feb 11, 2015 at 06:31 PM 0
Share

No, for that you need to use Application.Quit();

avatar image 686InSomNia686 · Dec 07, 2015 at 01:38 PM 0
Share

"EditorApplication.isPlaying = false;"

Exactly what I was searching, thanks :)

avatar image
1

Answer by AngryBurritoCoder · Feb 11, 2015 at 05:43 PM

If you are in unity ( playmode in unity ), it does not quit, otherwise you would lose your work. Try run a built version of the game and it should work.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by Unity_scat · Feb 28, 2016 at 09:18 AM

Apply

 Application.Quit();

To your code, then go to file then build and run. The code will not work if you're testing it from the scene editor.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image abubaker · Mar 18, 2016 at 06:45 PM 0
Share

I've got a strange problem with this one... Application.Quit(); works for me when playing in editor but not working after build... Any idea?

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

34 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

script not working on second character 1 Answer

DontDestroyOnLoad doesn't work 0 Answers

Menu script not showing up like normal 1 Answer

Following Script Not Working Properly 0 Answers

IEnumerator not working 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges