Search Issue Tracker

Won't Fix

Votes

0

Found in

2021.2

2022.1

Issue ID

1354144

Regression

No

UNITY_SERVER scripting define does not work when switching to Dedicated Server from Windows by script

Build Pipeline

-

How to reproduce:
1. Open attached project "ServerBuildScriptingDefine.zip" and scene "SampleScene"
2. In Build Settings window, switch to Windows, Mac, Linux platform.
3. In Editor Menu, click Bug -> Repro
4. After the build completes, observe Dedicated Server build's logs

Expected result: "It's a server!" messages are logged
Actual result: "It's a server!" messages are not logged

Reproducible with: 2021.2.0b5, 2022.1.0a4
Could not test with: 2019.4.29f1, 2020.3.15f1, 2021.1.16f1 (Dedicated Server functionality not implemented)

Note:
Issue does not reproduce when the platform is set to Dedicated Server prior to executing the script.

Note:
Issue is not restricted to dedicated server builds. Any time a call to BuildPipeline.BuildPlayer builds a player which platform and subtarget does not match the current active platform in the editor the issue will manifest itself. When platform is manually switched in the Editor's BuildPlayerWindow the problem does not occur because the editor window can detect when there's a mismatch and wait for scripts to be reloaded/recompiled with the new platform compiler macros to start the build. A temporary workaround for users relying on BuildPipeline.BuildPlayer would be to trigger the build a second time if unsure of what was the current active build platform or a reload scripts dialog appears right after the build is completed without the user changing anything.

  1. Response avatar

    Resolution Note (2022.1.X):

    Domain must reload before scripting defines are active. You must wait for domain reload after switching platform before building if you rely on the new platform defines.

Add comment

Log in to post comment

All about bugs

View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.