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.
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.
using UnityEngine;
using System.Collections;
public class MyInitializations : MonoBehaviour
{
public bool debugLog = false;
public bool runInBackgroundValue = true;
void Start ()
{
Application.runInBackground = true;
}
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);
}
}
}
}
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.
If you don’t have that option in the Player Settings, you probably don’t target PC platform. On Android and iOS this flag is ignored, so it’s not there, but it still affects the Editor. Go to PC player settings “Resolution and Presentation”, it will be there.