Keep Editor playing while in background
Is there a way to keep the Editor running it's play mode while in the background? Currently as soon as I focus another window, the Editor will suspend itself until focus is returned.
Answer by callen · Jun 28, 2016 at 06:53 PM
See: http://answers.unity3d.com/questions/9899/how-do-you-keep-your-game-running-even-when-you-sw.html
It's in Edit -> Project Settings -> Player
But... this comment from jashan seems important:
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.
yea the platform is set to iOS. Pretty silly that an Editor behavior would be tied to the Player Build settings. I suppose I could switch to Standalone during testing then switch back to iOS when I need to make a build :/
An alternative is to set Application.runInBackground inside Start or Awake to "true". Of course an iOS or Android application doesn't have such a setting since an App can't run in the background, only services.
The "player settings" is not an "editor setting" but a setting of the actual Unity player.
Good tip! This works:
void Awake () {
if (Application.isEditor)
Application.runInBackground = true;
}
Answer by Gwom · Jun 18, 2020 at 10:55 AM
If you want something for the editor, put the following in a script called RunEditorInBackground and put in a folder called Editor:
using UnityEngine;
using UnityEditor;
[InitializeOnLoad]
public class RunEditorInBackground : EditorWindow
{
// This constructor is called on load because of Initialise on Load tag
static RunEditorInBackground()
{
// Need to delay this as cant call EditorPrefs in static constructor
EditorApplication.playModeStateChanged += Running;
}
private static void Running(PlayModeStateChange obj)
{
if(EditorApplication.isPlaying)
Application.runInBackground = true;
}
}
Answer by JasonC_ · May 27, 2021 at 09:26 PM
Here; from the answers here I put a toggle for it in the editor menu; stick this in your Editor folder somewhere:
using UnityEditor;
using UnityEngine;
[InitializeOnLoad]
public class PlayInBackground : MonoBehaviour {
const string ITEM = "Edit/Play In Background";
static PlayInBackground () {
EditorApplication.delayCall += InitMenu;
}
static void InitMenu () {
Menu.SetChecked(ITEM, Application.runInBackground);
}
[MenuItem(ITEM, priority = 300)]
public static void TogglePlayInBackground () {
Menu.SetChecked(ITEM, !Menu.GetChecked(ITEM));
Application.runInBackground = Menu.GetChecked(ITEM);
}
}
The menu item will probably be down towards the bottom of the Edit menu.
That's a setting that's saved with the project already so it'll persist.
IMPORTANT: This is the same setting as "Run in Background" in the Build Settings, so if that setting is important for your platform, make sure it's set back to the correct value before a build!!
There's some bugs here in that the check state won't change if you change the Build Setting, and sometimes vice versa, but, I mean... I'm certainly not going to fix them. Seems to work well enough.
Your answer
Follow this Question
Related Questions
Long launch time 1 Answer
Entering Play mode is suddenly extremely slow 2 Answers
Manually unselect a handle in the editor from a script 0 Answers
Button disappearing when I start playmode 1 Answer
heterogeneous container in inspector 1 Answer