Search Unity

Lightmap and LightingDataAsset not working when loading a scene from an asset bundle

Discussion in 'Asset Bundles' started by zulaman, Apr 26, 2021.

  1. zulaman

    zulaman

    Joined:
    May 12, 2017
    Posts:
    26
    Hi there,
    I'm trying to make an assetbundle from a scene that has lighting baked into lightmaps and it's not loading correctly.
    The scene with all the geometry is loading correctly, but all the static objects that should receive a lightmap are marked non static and also the Contribute Global Illumination is checked off. When debugging in editor using the Scene View (Baked Lightmap) I can see that the lightmaps are assigned, but in Shaded mode the shader doesn't seem to use the lightmap affect.
    Lastly, if I select any of the objects and reassign the exact same shader (Standard) while still in play mode.... it fixes the issue and shows the affect of lightmap on the object.
    I can maybe hack it and iterate over every object in the scene and reassign the shaders again in runtime, but it just seems like a bug that needs to be fixed. or I'm possibly doing something else wrong.
    Thank you.
     
  2. zulaman

    zulaman

    Joined:
    May 12, 2017
    Posts:
    26
    For what it's worth.... here's the hack that fixed the issue for me.
    I just run it after loading the scene, but you have to wait till it's actually loaded with await or coroutine.

    Code (CSharp):
    1.                 MeshRenderer[] rnds = GameObject.FindObjectsOfType<MeshRenderer>();
    2.                 Shader shader = Shader.Find("Standard");
    3.                 foreach (MeshRenderer rnd in rnds)
    4.                 {
    5.                     Material mat = rnd.sharedMaterial;
    6.                     Shader origShader = mat.shader;
    7.                     mat.shader = shader;
    8.                     mat.shader = origShader;
    9.                 }
     
  3. zulaman

    zulaman

    Joined:
    May 12, 2017
    Posts:
    26
    Does anyone has a better solution ?
    This seems to work 90% of the time, but with some shaders it's not fully working.
     
  4. stamatian

    stamatian

    Joined:
    Jul 13, 2018
    Posts:
    36
    I'm having the same issue! Did you find a soultion? I'm using URP
     
  5. rstorm000

    rstorm000

    Joined:
    Aug 19, 2010
    Posts:
    229
    Did you figure out a solution for this?