Search Issue Tracker

By Design

Votes

0

Found in

2021.3.37f1

2022.3.26f1

2023.2.19f1

6000.0.0b16

Issue ID

UUM-71732

Regression

No

The baked lightmap does not show up in the Player when the lightmap is placed in a Prefab which is loaded dynamically

-

How to reproduce:
1. Open the “BakeLightBug“ project
2. Open the “Assets > Scenes > Scene2“
3. Enter the Play Mode
4. Press the space bar
5. Observe the Game view
6. Navigate to the “File > Build Settings“ and toggle on the Development Build
7. Build And Run
8. Observe the Player

Expected result: There are no lighting differences on the “cube“ GameObject between the Player and the Game view
Actual result: The “cube“ GameObject is darker in the Player than the Game view

Reproducible with: 2021.3.37f1, 2022.3.26f1, 2023.2.19f1, 6000.0.0b16

Reproducible on: macOS 13.5.2 (Intel), Windows 10 Pro (22H2)
Not reproducible on: No other environments tested

Workaround: Bake the “Scene2“ with the “Assets > Prefab > Cube.prefab“ added in the Hierarchy window, then delete the “Cube“ GameObject from the “Scene2“ Hierarchy window

Note: For the issue to be reproducible again after the workaround, delete all of the assets from the “Assets > Scenes > Scene2“ folder

  1. Resolution Note:

    The reason the lightmaps aren't showing up in the player is due to shader variant stripping. https://docs.unity3d.com/Manual/shader-variant-stripping.html

    To avoid an excessive amount of compiled shader variants in the final build, Unity checks which variants are actually used by the scenes contained in the build. Since the build contains no scenes with any lightmapped objects in this case (only a script which will load a prefab at runtime), Unity assumes that the shader variants used to render lightmapped objects aren't needed, and strips them.

    To solve this, you have 2 options:
    1. Include at least 1 scene with 1 lightmapped object (which is NOT loaded at runtime) in the build. Including such a scene will cause Unity to determine that lightmap variants are needed, and include them in the build.
    2. Manually configure lightmap variants to be included. This can be done in Project Settings, under the Graphics tab. In the "Shader Stripping" section, there is a dropdown named "Lightmap Modes". This is set to automatic by default, which means that Unity will automatically try to determine whether to strip lightmap variants. You can set this to custom, and check the relevant checkboxes in order to force lightmap variants to be included. Note that this may increase build times.

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.