Skip to content

Gate the native engine on the host OS, not the active build target - #439

Open
MonoFinity wants to merge 1 commit into
Voltstro-Studios:masterfrom
MonoFinity:fix/host-os-engine-gate
Open

Gate the native engine on the host OS, not the active build target#439
MonoFinity wants to merge 1 commit into
Voltstro-Studios:masterfrom
MonoFinity:fix/host-os-engine-gate

Conversation

@MonoFinity

@MonoFinity MonoFinity commented Jul 27, 2026

Copy link
Copy Markdown

The problem

UWB picks its native engine off the Unity active build target, but the engine is a native child process of the running Unity process — so in the Editor, the platform that matters is the one the Editor itself is running on.

Because the selection is keyed on UNITY_STANDALONE_* alone, a Windows Editor whose active build target is WebGL, Android or a console compiles:

  • WebBrowserUtils.GetRunningPlatform() down to throw new PlatformNotSupportedException(), and
  • EngineProcess's constructor down to nothing, leaving processHandle null so every member forwarding to it throws a NullReferenceException.

The practical effect is that UWB cannot be used in the Editor at all by any project that is not currently targeting Standalone. There is no runtime override for it — it's a compile-time gate, so no Engine subclass hook or asmdef arrangement works around it. Switching the build target to Standalone just to preview a webview is disruptive on a large project (it forces an asset re-import and invalidates the platform's script defines).

The change

Widen each gate to UNITY_STANDALONE_X || UNITY_EDITOR_X in the six places that select or compile the per-platform process wrapper:

File Gate
Helper/WebBrowserUtils.cs GetRunningPlatform()
Core/Engines/EngineProcess.cs ctor processHandle selection
Core/Engines/EngineConfiguration.cs GetEngineExecutableName() — a Windows Editor must still look for the .exe
Core/Engines/Process/WindowProcess.cs file guard
Core/Engines/Process/LinuxProcess.cs file guard
Core/Engines/Process/MacOsProcess.cs file guard

Player builds are unaffected

This only widens what compiles inside the Editor. A Standalone player defines UNITY_STANDALONE_X but not UNITY_EDITOR_X; a WebGL/Android player defines neither. Both keep the existing behaviour byte-for-byte.

Notes

  • Verified against master (f49743d).
  • We've been running this patch in a vendored copy of 2.2.8 for production Editor work on Windows, hosting a CEF-rendered React UI in the Game View with the build target set to WebGL.
  • Sent as a separate PR from Bound the TCP client's connect timeout instead of int.MaxValue #440 — the two are independent and either can be taken without the other.

The engine is a native child process of the running Unity process, so in the
Editor the platform that matters is the one the Editor itself runs on. Keying
the platform selection off UNITY_STANDALONE_* alone means a Windows Editor
whose active build target is WebGL, Android or a console compiles
WebBrowserUtils.GetRunningPlatform() down to
`throw new PlatformNotSupportedException()`, and EngineProcess leaves
processHandle null so every member forwarding to it throws a
NullReferenceException. UWB is therefore unusable in the Editor for any
project not currently targeting Standalone.

Widen each gate to UNITY_STANDALONE_X || UNITY_EDITOR_X in the five places
that select or compile the per-platform process wrapper, plus
GetEngineExecutableName so a Windows Editor still looks for the .exe.

Player builds are unaffected: a Standalone player defines only
UNITY_STANDALONE_X and a WebGL/Android player defines neither, so both keep
the existing behaviour exactly. The change only widens what compiles inside
the Editor.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Comment on lines +35 to +39
#if UNITY_STANDALONE_WIN || UNITY_EDITOR_WIN
processHandle = new WindowProcess();
#elif UNITY_STANDALONE_LINUX
#elif UNITY_STANDALONE_LINUX || UNITY_EDITOR_LINUX
processHandle = new LinuxProcess(logger);
#elif UNITY_STANDALONE_OSX
#elif UNITY_STANDALONE_OSX || UNITY_EDITOR_OSX

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A more better way would be to check the editor platform first, then check the target platform only if the build is not an editor. That way if someone is using Linux editor with the target set to Windows, it will start the Linux process in editor.

#if UNITY_EDITOR_WIN || (!UNITY_EDITOR && UNITY_STANDALONE_WIN)
            processHandle = new WindowProcess();
#elif UNITY_EDITOR_LINUX || (!UNITY_EDITOR && UNITY_STANDALONE_LINUX)
            processHandle = new LinuxProcess(logger);
#elif UNITY_EDITOR_OSX || (!UNITY_EDITOR && UNITY_STANDALONE_OSX)
            processHandle = new MacOsProcess();
#endif

Comment on lines +32 to +33
//Host-OS gate: a Windows Editor must still look for the .exe whatever the build target.
#if UNITY_STANDALONE_WIN || UNITY_EDITOR_WIN

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as comment on EngineProcess.

Comment on lines +149 to +153
#if UNITY_STANDALONE_WIN || UNITY_EDITOR_WIN
return Platform.Windows64;
#elif UNITY_STANDALONE_LINUX
#elif UNITY_STANDALONE_LINUX || UNITY_EDITOR_LINUX
return Platform.Linux64;
#elif UNITY_STANDALONE_OSX
#elif UNITY_STANDALONE_OSX || UNITY_EDITOR_OSX

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as comment on EngineProcess.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants