When I run my app I watch the play button. and on press I run this
void OnDisable()
{
Debug.Log(“Shutting down”);
shutdown();
}
but we need to do the close manually from a c# app out side of unity. I was hoping there was a better way of doing this then using a socket connection of sorts. We did try a find app. cose using winAPI but I need the OnDisable function needs to be run.
Any thoughts?
OnDisable is a GameObject related thing. What you want to know is… “Does the window have focus?” The answer to that is… Unity does not support the System.Windows.Forms, so seeing which window has focus is not an option for you.
The answer is No.
There, however may be some connection between Application.runInBackground and what you want though, but I do not know of a way to see if you are actually in the background.
thanks for the reply, I think I explained that a bit wrong. that or I didnt follow you perfectly. I’m not looking to use windows forums in unity but rather control unity from another app.
We did this:
Find the unity window.
kill the process.
The unity app closed but no cleanup was done on the c++ side ( i.e. shutdown(), ran inside of onDisable ).
we also tried a close process in hopes the kill was too aggressive. Though it seemed it also was not running the c++ cleanup. I’m pretty certain clicking the close button works. I’d have to debug it to be sure, but I’d expect the onDisable would be used outside the unity editor, right?
if not, is there a callbacked when closing the unity app I can use? OnApplicationQuit maybe?
Ok did some more testing and its not a unity issue.
ran my unity app hit alt f4 and both of those function are run.
ran my unity app used TaskManager to end task and neither of those function are run.
So I guess my question would be, any way to know if the task is ended? IMO, I’d think not.
Looks like you can call coroutines via the Application.OnApplicationQuit function. There’s example code for showing a splash screen prior to Application.Quit @ Unity - Scripting API: Application.CancelQuit
Turns out , closeMainWindow did the trick from the application trying to close unity.
close, does not actuality close it down. Kill was the same as end task. closing with closeMainWindow works nicely.