You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is actually expected behavior caused by the "Focus Nudge" feature, not a bug.
What's happening
When Unity runs in the background on macOS, the OS aggressively throttles it (App Nap), which can cause PlayMode tests to stall completely. To work around this, unity-mcp temporarily switches focus to Unity when it detects a test job is stalled, allowing Unity to make progress, then returns focus to your previous app.
The "Electron launching" you're seeing is VSCode (which is built with Electron) being refocused when Unity returns focus to it after the nudge.
Why this is needed
Without this nudge mechanism, PlayMode tests can hang indefinitely on macOS when Unity is in the background because the OS puts it to sleep. This is a well-known macOS behavior affecting background applications.
Options if this is disruptive
Keep Unity focused - No nudges will occur if Unity is already the frontmost app
Adjust nudge behavior via environment variables:
UNITY_MCP_NUDGE_DURATION_S=3 - How long Unity stays focused (default 3s)
UNITY_MCP_NUDGE_BASE_INTERVAL_S=5 - Minimum time between nudges (default 1s)
UNITY_MCP_NUDGE_MAX_INTERVAL_S=30 - Max interval between nudges (default 10s)
Disable focus nudging - If you set UNITY_MCP_NUDGE_BASE_INTERVAL_S to a very large value (like 999999), nudges will effectively never happen
Note: If tests are completing successfully despite the window switching, everything is working as designed—the window switching is the trade-off for allowing background Unity tests to run on macOS.
Let me know if you'd like a dedicated environment variable like UNITY_MCP_ENABLE_FOCUS_NUDGE=false to completely disable this feature!
Interesting. No, it's all good. I don't need an env for it.
But I don't understand why it launches a new window of Electron itself. Not VSCode or something. Literally Electron. Quite confusing. Because focusing back on VSCode shouldn't be launching Electron, right?
Confirmed from current code: this is a real macOS focus-restore bug in focus_nudge.py.
Current flow stores only the frontmost process name (via System Events), then restores focus with: tell application "<process_name>" to activate.
For some Electron-based IDE setups, the process name can be generic (for example "Electron"), which can cause macOS to activate/launch a different app target (e.g. Electron.app) instead of restoring the original IDE window.
Suggested direction:
capture (bundle_id, pid, process_name) for the original foreground app
restore in order:
tell application id "<bundle_id>" to activate
fallback by pid via System Events
fallback by process name via System Events
avoid direct tell application "<generic_process_name>" for names like Electron
@dsarno would you mind taking a look when you have a chance? . I don't have a macOS device right now.
Fix implemented in PR #783. The macOS focus-restore now captures the bundle identifier alongside the process name and uses tell application id "<bundle_id>" to activate when restoring focus.
Root cause: VS Code's process name is "Electron", so tell application "Electron" to activate launched a standalone Electron instance instead of returning to VS Code.
What changed in focus_nudge.py:
_get_frontmost_app_macos() now retrieves both process name and bundle ID via a single AppleScript call (with a guard for processes that have no bundle ID)
_focus_app_macos() prefers tell application id "com.microsoft.VSCode" to activate (or whatever the actual bundle ID is), falling back to name-based activation if bundle ID fails
Windows/Linux unaffected -- they use window titles and window IDs respectively
Hey @dsarno I haven't had a chance to test this out yet. Apologies for the late reply. I'll confirm this is fixed the next time I work on my game! Thanks a ton :)
Activity
[-]Get Test Job launching Electron[/-][+][Bug] Get Test Job launching Electron[/+]whatevertogo commentedon Feb 11, 2026
Hi @materwelonDhruv, thanks for the report!
This is actually expected behavior caused by the "Focus Nudge" feature, not a bug.
What's happening
When Unity runs in the background on macOS, the OS aggressively throttles it (App Nap), which can cause PlayMode tests to stall completely. To work around this, unity-mcp temporarily switches focus to Unity when it detects a test job is stalled, allowing Unity to make progress, then returns focus to your previous app.
The "Electron launching" you're seeing is VSCode (which is built with Electron) being refocused when Unity returns focus to it after the nudge.
Why this is needed
Without this nudge mechanism, PlayMode tests can hang indefinitely on macOS when Unity is in the background because the OS puts it to sleep. This is a well-known macOS behavior affecting background applications.
Options if this is disruptive
UNITY_MCP_NUDGE_DURATION_S=3- How long Unity stays focused (default 3s)UNITY_MCP_NUDGE_BASE_INTERVAL_S=5- Minimum time between nudges (default 1s)UNITY_MCP_NUDGE_MAX_INTERVAL_S=30- Max interval between nudges (default 10s)UNITY_MCP_NUDGE_BASE_INTERVAL_Sto a very large value (like 999999), nudges will effectively never happenNote: If tests are completing successfully despite the window switching, everything is working as designed—the window switching is the trade-off for allowing background Unity tests to run on macOS.
Let me know if you'd like a dedicated environment variable like
UNITY_MCP_ENABLE_FOCUS_NUDGE=falseto completely disable this feature!Written By Agent.
materwelonDhruv commentedon Feb 18, 2026
Interesting. No, it's all good. I don't need an env for it.
But I don't understand why it launches a new window of Electron itself. Not VSCode or something. Literally Electron. Quite confusing. Because focusing back on VSCode shouldn't be launching Electron, right?
whatevertogo commentedon Feb 18, 2026
Confirmed from current code: this is a real macOS focus-restore bug in
focus_nudge.py.Current flow stores only the frontmost process name (via System Events), then restores focus with:
tell application "<process_name>" to activate.For some Electron-based IDE setups, the process name can be generic (for example
"Electron"), which can cause macOS to activate/launch a different app target (e.g.Electron.app) instead of restoring the original IDE window.Suggested direction:
(bundle_id, pid, process_name)for the original foreground apptell application id "<bundle_id>" to activatetell application "<generic_process_name>"for names likeElectron@dsarno would you mind taking a look when you have a chance? . I don't have a macOS device right now.
dsarno commentedon Feb 18, 2026
Yes I'll look thank you @whatevertogo
Fix focus nudge launching Electron instead of restoring VS Code on macOS
dsarno commentedon Feb 19, 2026
Fix implemented in PR #783. The macOS focus-restore now captures the bundle identifier alongside the process name and uses
tell application id "<bundle_id>" to activatewhen restoring focus.Root cause: VS Code's process name is
"Electron", sotell application "Electron" to activatelaunched a standalone Electron instance instead of returning to VS Code.What changed in
focus_nudge.py:_get_frontmost_app_macos()now retrieves both process name and bundle ID via a single AppleScript call (with a guard for processes that have no bundle ID)_focus_app_macos()preferstell application id "com.microsoft.VSCode" to activate(or whatever the actual bundle ID is), falling back to name-based activation if bundle ID failsThis will ship in the next beta release.
Fix focus nudge launching Electron instead of restoring VS Code on ma…
dsarno commentedon Feb 19, 2026
@materwelonDhruv Would you mind testing to see if this works for you? It's on the beta branch, which you can install into unity with this link:
https://github.com/CoplayDev/unity-mcp.git?path=/MCPForUnity#betaFix focus nudge launching Electron instead of restoring VS Code on ma…
Fix focus nudge launching Electron instead of restoring VS Code on ma…
materwelonDhruv commentedon Feb 26, 2026
Hey @dsarno I haven't had a chance to test this out yet. Apologies for the late reply. I'll confirm this is fixed the next time I work on my game! Thanks a ton :)