• 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
Question by davidaayers · Nov 28, 2014 at 08:32 PM · quitapplication.quit

Application.Quit needs to be called twice?

I have a simple Quit button in my game that calls Application.Quit. And it works. Except you have to hit it twice. I can log and see that the button is being pressed twice, and it appears application.quit is called twice.

I do have a couple of game objects with OnApplicationQuit() methods; they are used to save the game and to save the user's preferences when they quit the game. They are successfully invoked (twice).

I've searched around a lot and can't seem to find anyone having a similar problem.

I'm not doing this from the editor either :)

Comment
Kuptsevych-Yuriy

People who like this

1 Show 5
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 Radetic · Aug 03, 2015 at 07:51 PM 0
Share

Hi, do you call Application.CancelQuit() on the body of any Monobehaviour.OnApplicationQuit() ??? This might explain why it has to call Application.Quit() twice in order to really finish the process.

avatar image meat5000 ♦ · Aug 03, 2015 at 08:23 PM 0
Share

No gameobjects should exist at the point that OnApplicationQuit is called, I do believe, as OnDestroy runs before it, which marks the destruction of all the objects. Do you have some gameobject being created in OnDestroy?

avatar image Radetic · Aug 03, 2015 at 08:36 PM 0
Share

@meat5000: do you know any reference for the order in which these events take place ??

I'm trying to open a confirm quit dialog using Application.CancelQuit() at the body of Monobehaviour.OnApplicationQuit. It turned out badly.

avatar image meat5000 ♦ · Aug 03, 2015 at 11:12 PM 1
Share

Yarp. Here it is

http://docs.unity3d.com/Manual/ExecutionOrder.html

avatar image Radetic · Aug 04, 2015 at 02:19 PM 0
Share

Found it yesterday, thanks a lot! Will try native OS functions and a lot of workarounds for my case.

0 Replies

· Add your reply
  • Sort: 

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

How to find what crashes my game? Is there a dump file? 1 Answer

Application.Quit Does Not Fully Kill App 1 Answer

Can I make my Android game close if you leave the game on the title screen? 1 Answer

How to Exit Application in Android on Back Button 3 Answers

OnApplicationQuit not working on android 0 Answers


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