Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by MomosArts · Aug 15, 2018 at 01:24 PM · not workingstandalonefunction call

Application.Quit does not quit built Application

Hello everyone! This is my first time asking a question here, since this time Google could not help me :D

So I have my game and a button that calls following function:

 public void ExitGame() {
         Debug.Log("Function called.");
         #if UNITY_EDITOR
             UnityEditor.EditorApplication.isPlaying = false;
         #else
             Application.Quit();
         #endif
     }

I'm sure I'm just missing some ridiculous detail, but I can't get the application to quit as soon as it's built. It definitely goes into the function since it logs the "Function called.", and in the editor, it exits the game as well. Just in the standalone app, nothing happens. Are there any settings I might have missed?

Thank you all in advance! :)


EDIT: I have a GameObject named "GameManagers" that has a QuitGame script on it. the script looks as follows:

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class QuitGame : MonoBehaviour {
 
     private bool exitButtonPressed;
 
     void Start() {
         exitButtonPressed = false;
     }
 
     void Update() {
         if(exitButtonPressed) {
             ExitGame();
         }
     }
 
     public void SetExitButtonPressed(bool wasPressed) {
         exitButtonPressed = wasPressed;
     }
 
     private void ExitGame() {
         #if UNITY_EDITOR
             UnityEditor.EditorApplication.isPlaying = false;
         #else
             Application.Quit();
         #endif
     }
 }

The method SetExitButtonPressed is called through clicking a button which uses the usual Button Event System Unity provides. It makes no difference if the button calls the ExitGame method directly, or if I set the Boolean exitButtonPressed to true, and call the method in the Update function as soon as the Boolean turns true. Both ways lead to everything workung fine in the editor, but in the built game, the function is not called.

Comment
Add comment · Show 8
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 Hellium · Aug 15, 2018 at 01:48 PM 0
Share

Which platform do you target? There is no reason this would not work.

avatar image MomosArts Hellium · Aug 15, 2018 at 02:22 PM 0
Share

I built the game for windows - and I am at my wits' end with why it does not work, I know it should do...

avatar image Hellium · Aug 15, 2018 at 02:33 PM 0
Share

How ExitGame is called? Who calls it? When? How do you know the function is called in the built game?

avatar image MomosArts Hellium · Aug 15, 2018 at 03:00 PM 0
Share

Hmm, I just added a line of code that would just set a random GameObject in the Scene inactive, so that I would see whether the function was called or not, and the function is indeed not called in the built game. I've attached a screenshot of how the function is called.

EDIT: On the screenshot, it calls a function that sets a boolean to true, and the ExitGame function is called as soon as the boolean goes true. This was an attempt of a workaround that sadly didn't change the situation. alt text

button-event.png (6.3 kB)
avatar image Hellium MomosArts · Aug 15, 2018 at 03:23 PM 0
Share

Can you edit your question and provide the relevant code? (the SetExitButtonPressed and the function that checks whether the boolean is set to true)

Show more comments

1 Reply

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

Answer by MomosArts · Aug 15, 2018 at 04:16 PM

Okay, I eventually found a solution, although I have no idea why it doesn't work the other ways I've tried. Instead of having the QuitGame script on a separate GameObject, and then assigning the button the function by dragging the GameObject with the script on it into the Button Event in the inspector, I put the QuitGame script onto the button itself. And now it works without me having changed the code... I probably had a mess of protection levels there :)

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

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

154 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 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 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 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 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

Unable to call function from another script 0 Answers

Game plays in editor but crashes standalone 0 Answers

XinputDotNetPure and XInputInterface: They work flawlessly in Editor, but Standalone build can't find them. 1 Answer

ScreenResolution is not being reset Unity 0 Answers

how to attach scripts in unity for going to next level 2 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