1

Is it possible to run code before the Unity player is closed (by closed, we mean all ways of closing the program, either by Alt+F4, pressing the X button on the window corners, closed from within the game, etc.)? If yes, how?

brain56
  • 2,659
  • 9
  • 38
  • 70
  • If it were WinForms, you'd want to subscribe to the `FormClosing` or `FormClosed` event. Not sure if Unity3D supports that, though... – Nolonar Aug 14 '13 at 07:29
  • 2
    Is it [OnApplicationQuit](http://docs.unity3d.com/Documentation/ScriptReference/MonoBehaviour.OnApplicationQuit.html) ? – Matthew Watson Aug 14 '13 at 07:42
  • Awesome. That seems so trivial I feel so dumb. Could you post that as an answer so I can accept it, please? – brain56 Aug 14 '13 at 08:05

1 Answers1

2

You need to use the OnApplicationQuit() method.

Matthew Watson
  • 104,400
  • 10
  • 158
  • 276