# Unity Application.Quit() doesn't work

In the update, I have set up a counter so that after 140 frames, Unity will quit the game. But this quit command doesn't quit and it just continues to play the game. What am I doing wrong? I am using and testing in Unity 2D. There are no errors and all the prints are visible.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Normal_Car : MonoBehaviour
{
private int counter = 0;

public Vector3 finalPos = new Vector3(0.00f,0.00f,0.00f);

public Transform t;

// Start is called before the first frame update
void Start()
{
t.GetComponent<Transform>();
}

// Update is called once per frame
void Update()
{
print("Frame: " + counter.ToString());
counter += 1;
t.position += finalPos;
if(counter >= 140)
{
Application.Quit();
print("Quit!");
}
}
}

• What do you mean by "doesn't work"? Your build crashes? Shows errors? It does something else? It does nothing? Is the print output visible? Are you testing this inside the editor or in a build? – Tyyppi_77 Oct 24 at 16:44
• Your edit only adresses part of my questions. Where are you testing this? Are the print outputs visible? Are there any errors? – Tyyppi_77 Oct 24 at 17:08
• I am testing in Unity and there are no errors. All the prints are visible. – DragonflyRobotics Oct 24 at 17:19

If you check out the documentation for Application.Quit it starts by saying this:

Quits the player application. Shut down the running application. The Application.Quit call is ignored in the Editor.

Application.Quit does nothing if you test inside the editor.

• Okay, then is there any other way to text this without having to export something every time? Thank you for helping. – DragonflyRobotics Oct 24 at 18:04
• Test what? Test the Application.Quit() implementation? Is it not enough to for an example debug log something before calling Application.Quit() and verifying that it is output correctly? Also a quick googling of "unity stop editor" yields this among other things: answers.unity.com/questions/161858/… if you want to stop the editor playing instead. – Tyyppi_77 Oct 24 at 18:20
• Yes, I meant to stop the editor as a place holder for testing my game. – DragonflyRobotics Oct 24 at 20:25

I think it's this.Quit(); That might just be in WinForms though :)

• "I think" — did you try researching or testing this suggestion to have more confidence that it applies in Unity? – DMGregory Oct 25 at 12:22
• @DMGregory I was following a tutorial for WinForms and he said 'do this.quit(); to make a quit button' – Busaruba2011 Oct 25 at 12:34
• Is this question about WinForms? – DMGregory Oct 25 at 12:34
• No, but WinForms uses C# and unity uses that too. – Busaruba2011 Oct 25 at 12:39
• this refers the the current object, the object of the class that owns the code where this is written. this will mean a different object depending on where it is written. You might want to read up a bit more on the topic. – Vaillancourt Oct 25 at 13:47