Entities player build Fog and Lightmap issue workaround

With the release of Entities Graphics as part of ECS for Unity, we are aware of an existing issue with regards to Fog and Lightmaps in player builds. If you are having issues with fog or lightmap rendering with entities in subscene in player builds, where entities are not rendering the same as GameObjects, we’re providing a workaround that would be useful.

This workaround is targeted specifically at com.unity.entities.graphics 1.0.8 and above.

Specifically, the root cause is that the build pipeline always strips entities shader keywords according to the settings on the subscenes. This can be a problem when the subscene settings are different from the main scene where the entities will be rendered. In such cases, entities may be rendered with an unexpected setting for fog and/or lightmaps. This is not an issue when the main scene has the same settings as the subscene.

The Workaround

The workaround is simple, you can open the subscene and apply the same fog / lighting settings on the Lighting Panel as the main scene. If you have a lot of scenes and subscenes in your project, you can use the tool below instead of editing each of the subscenes manually.

* You can also go to ProjectSettings > Graphics > Shader Stripping > On Lightmap Modes / Fog Modes, select Custom and select the settings you need. However this method will enable the corresponding Fog / Lightmap shader keywords for all the shaders. This means more unused shader variants might be included in player build, lengthened player build time and affect runtime memory.

SubsceneLightingSync tool

To use it:

  1. Make sure you’ve backup the project
  2. Download the SubsceneLightingSync.cs script attached to this post
  3. Put the script in any “Editor” folder under Assets/
    9048217--1250104--upload_2023-5-31_17-16-29.png
  4. On top menu > click “Sync all scenes in project” to sync fog and lighting settings for all of the subscenes in the project
    9048217--1250101--upload_2023-5-31_17-16-29.png
    Note that the script only processes scenes under the Assets folder.
    Feel free to edit the script to match your own needs.
  5. The editor console will print a message to tell what scenes are synced:
  6. You can also “Enable auto sync per scene saving” which the script will automatically sync the settings to a scene’s subscenes whenever a scene is saved.

Note:

  • If you have auto sync ON - scene saving might take longer as it needs to also save the subscenes.
  • If you have auto sync OFF - you will have to remember to click “Sync all scenes in project” before player building.
  • For multi-scene set up - the fog / lightmap mode settings will be taken from the scene that the subscene belongs to. Feel free to edit the script to match your own needs.
  • If you have baked lightmaps for objects in subscene (entities), make sure the same subscene is not shared in multiple scenes as this is not supported (more details in known issues).

9048217–1250113–SubsceneLightingSync.cs (5.11 KB)

2 Likes