Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Official Entities player build Fog and Lightmap issue workaround

Discussion in 'Graphics for ECS' started by mingwai, May 31, 2023.

  1. mingwai

    mingwai

    Small Graphics Potato Unity Technologies

    Joined:
    Jan 16, 2017
    Posts:
    52
    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.

    upload_2023-5-31_17-14-3.png

    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/
    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
    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:
    upload_2023-5-31_17-16-29.png
    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).
     

    Attached Files:

    lilacsky824 and Anthiese like this.