Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question Wrong lightmaps baked into asset bundles

Discussion in 'Asset Bundles' started by JMota7, May 10, 2022.

  1. JMota7

    JMota7

    Joined:
    Nov 15, 2017
    Posts:
    6
    Hi,

    After reading some literature about lighting and asset bundles (I've attached a few links below), I couldn't get the lighting from a scene (or even a prefab) from an asset bundle previously uploaded to a server.

    After baking the scene in my AssetBundle builder project I have something like this:

    upload_2022-5-10_21-24-52.png

    After that, I've tried to build two different asset bundles:
    1. "Night_light" scene
    2. "Root" prefab (the same prefab baked in the Asset Bundle builder project)
    Result:

    upload_2022-5-10_20-42-21.png

    Also, I've tried this -> https://github.com/Ayfel/PrefabLightmapping baking the lights into the prefab, building as an asset bundle and instantiating it afterwards in another project (downloading it from the server).

    Result:

    upload_2022-5-10_20-45-38.png


    upload_2022-5-10_21-25-11.png

    And finally, I've also tried this -> https://github.com/laurenth-personal/lightmap-switching-tool

    In this case, it crashes directly or shows lights wrongly (without using Asset Bundles):

    upload_2022-5-10_23-37-51.png

    I've played with different options from "Shader Stripping" switching from "Automatic" to "Custom", clicking on the "Import From Current Scene" button, enabling "Baked Non-directional", "Baked Directional", "Baked Shadowmask" and "Bake Subtractive", switching also between those lighting modes in the lighting tab.

    I don't mind getting the lights from two different scenes or from two different prefabs (it would be better for me to get it from prefabs, but it could be both options).

    I'm using:

    Universal Render Pipeline (using most of the materials with shader Universal Render Pipeline/Lit)
    Unity 2020.3.0f1

    I've been reading those links but I don't know which one could be the problem that causes this. Can anybody help me with this?

    Thanks!

    P.S. I wasn't sure if I should post this into this subforum instead of lighting.

    https://forum.unity.com/threads/assetbundle-cant-load-the-lightmap.666304/
    https://forum.unity.com/threads/problems-with-instantiating-baked-prefabs.324514/
    https://forum.unity.com/threads/baked-lighting-on-prefabs-dynamically-generated-level.930534/
    https://forum.unity.com/threads/lightmaps-ignored-at-scene-loaded-from-assetbundle.670351/

    https://unity.com/how-to/advanced/optimize-lighting-mobile-games

    https://github.com/Ayfel/PrefabLightmapping
    https://github.com/guiglass/Lighting-Scenario-Switcher
    https://github.com/laurenth-personal/lightmap-switching-tool
     
    Sohjiro and amdplaneta like this.
  2. Alex_Heizenrader

    Alex_Heizenrader

    Joined:
    May 16, 2019
    Posts:
    89
    If you want to bake in the prefab then you need to have the same settings in both projects, the one where you baked and the one where you load the bundle. Specifically the Lightmap encoding setting and the included shaders in both. I do know it works because we do the same, bake prefabs, assetbundle to server and load in a different project, and with the Ayfel tool you pointed out
     
    JMota7 likes this.
  3. JMota7

    JMota7

    Joined:
    Nov 15, 2017
    Posts:
    6
    I've just done an identical copy of the project and downloaded the AssetBundle using the PrefabLightmapping from Ayfel but it still happens the same thing. Do you have any kind of compression when you build the bundles? Could be related to the weight of the AssetBundles?

    I've tried saving the lights into the prefab and exporting the AssetBundle into a new empty project, and the lights are correctly shown. But if I try to instantiate the prefab after downloading it from the AssetBundle the lights are totally corrupted.
     
  4. JMota7

    JMota7

    Joined:
    Nov 15, 2017
    Posts:
    6
    By any chance... Are you using URP also for your project?