- Home /
How to keep Unity rendering when focus is not set to game window
Im using UDP to control the unity environment. Ive written a test app to send data into unity that consists of a dozen buttons, faders, and some XY pads. When i set OSX's focus to my test app (read: select the test app as the active application in the title bar), unity stops re-drawing the game. Essentially i either need to run the app on a second machine, which is a PITA when i am just knocking things around on my laptop (95% of my dev cycle) - or write automated code inside my test app which simulates human interaction with the app (which i have done already).
Does anyone have a solution for getting Unity to keep drawing, even when focus is not set to it within the OS?
Answer by asafsitner · Oct 04, 2011 at 09:02 PM
Put Application.runInBackground = true;
somewhere in your code and you should be good to go.
See the documentation: http://unity3d.com/support/documentation/ScriptReference/Application-runInBackground.html
You can also set this somewhere in the project settings but i also prefer setting it via script ;)
Edit-->Project Settings-->Player-->Resolution and Presentation-->Run In Backgound
Right. I always forget about that one... which is why I always set it via script. :)
Actually, I can still get it (this is Unity 5.4.5f1). It happens when I have an OpenGL rendering window active as well as the Unity player. When activing my own OpenGL window (Unity still running in the background), after 5 seconds or so the Unity window stops rendering. When I use my keyboard, it stays paused. When I move my mouse, it becomes active again for 5 seconds. When I $$anonymous$$imize my own OpenGL window, Unity keeps rendering. Would be good to even continue rendering even when I'm active myself in another window.
Answer by KevinCook · Apr 14, 2015 at 05:27 PM
No need to add code. There's a tickbox in the player settings.
Go to Edit->Project Settings->Player, select the 'Standalone' tab, and 'Resolution & Presentation'. Now check the 'Run In Background' tickbox.
Answer by Timurov · Feb 01, 2013 at 03:25 PM
many thanks guys! I've been looking that so many times :)
This should be added in the comment area by using the "add new comment" link, not in the area reserved for answers.