- Home /
How do you keep your game running even when you switch out of it?
Whenever I run my game in unity or build a standalone, it works fine. When I alt-tab out of it or switch to another program, the program stops going and then continues right where I left off when I come back to it.
I want the game to continue running while I am switched out. Is this possible?
The reason I want to do this is that I'm making a dedicated server and client. I want both programs to continue to run in the background.
Thanks for your help!
Answer by burnumd · Jan 08, 2010 at 06:31 PM
In the editor, go to Edit -> Project Settings -> Player. The inspector pane will now change to show the player settings. Look for the option that says "Run In Background" and check it.
This option will be held in both the editor preview and in built games.
This option seems to have disappeared in 3.5. Where do we find it now?
This should be a comment to the accepted answer, not a new question.
This option does not seen to exist in 3.5.6f4 does anyone know how to do this anymore ?
This should be a comment to the accepted answer, not a new question.
Some people aren't finding this in more recent versions of Unity. But it's still there: In Player settings, under the section "Resolution and Presentation", you find "Resolution" and below that, there's "Run In Background".
This is only available for Web players and standalones, though (you won't find it when you have the iOS, Android or Flash tab selected.
thanks was wandering for how to program and improve code while I wait 20 $$anonymous$$ for program to run to see resaults
Answer by JazzCat-9 · Nov 16, 2015 at 05:40 PM
In Unity 5.1.4, I've found that Edit -> Project Settings -> Player -> "Run In Background" checkbox only works when it is checked while Unity Editor is playing, (that it won't stay checked for future plays in Unity Editor, nor when making a build).
So, I've just triggered the setting in an initialization script tied to a root GameObject, and that seems to work fine.
(NOTE: I'm using 5.1.4 instead of the most recent build because the 5.2.x series seems to have broken microphone input. :/ )
using UnityEngine;
using System.Collections;
public class MyInitializations : MonoBehaviour {
public bool debugLog = false;
public bool runInBackgroundValue = true;
void Awake () {
}
// Use this for initialization
void Start () {
Application.runInBackground = true;
}
// Update is called once per frame
void Update () {
if (debugLog) {
runInBackgroundValue = Application.runInBackground;
}
if (!Application.runInBackground) {
Application.runInBackground = true;
if (debugLog) {
Debug.Log("Re-Setting Application.runInBackground to TRUE at: " + Time.time);
}
}
}
}
Answer by james.jeffers · Feb 11, 2010 at 02:56 PM
Apparently this does not work in Safari (Mac OS) for Unity v2.6.1.
Answer by CliveHazel · Jun 04, 2016 at 03:59 PM
In Unity 5.1.4, I've found that Edit -> Project Settings -> Player -> "Run In Background" checkbox only works when it is checked while Unity Editor is playing, (that it won't stay checked for future plays in Unity Editor, nor when making a build).
So, I've just triggered the setting in an initialization script tied to a root GameObject, and that seems to work fine.
^^^^
is that working on android??