Search Issue Tracker

Won't Fix

Under Consideration for 2021.3.X, 2022.3.X

Votes

0

Found in

2021.3.27f1

2022.3.2f1

Issue ID

UUM-39993

Regression

No

Conditional compilation directives like #if UNITY_EDITOR are ignored when building the project

-

Reproduction steps:
1. Open the “compilerErrorOnBuild“ project
2. Open the “SampleScene“ scene
3. Build the project
4. Build And Run the project using the Build Settings window

Expected result: Both builds are successful
Actual result: A build fails due to an error caused in `OnValidate` which is inside a `#if UNITY_EDITOR` directive

Reproduced in: 2020.3.48f1, 2021.3.27f1, 2022.3.2f1
Not reproduced in: 2023.1.0a1, 2023.1.0f1, 2023.2.0a19
Already fixed in: 2023.1.0a1

Reproduced using: Windows 10 (by the reporter), Windows 11, macOS 13.4 (Intel)

Note: The reproduction was inconsistent. E.g. the issue went away after performing a “Reimport All”

  1. Resolution Note:

    OnValidate is called when Scene is loaded.
    When we build players, we also first load the scenes in the Editor to know what Assets are used so we only copy what is needed.
    OnValidate are only called in the Editor, so thats why the `#if UNITY_EDITOR` do not exclude ty8s c

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.