Search Unity

No lightmaps when loading assetBundle

Discussion in 'Editor & General Support' started by roka, Jun 29, 2015.

  1. roka

    roka

    Joined:
    Sep 12, 2010
    Posts:
    598
    Hello,

    I'm using Unity 5.1.0f3.

    I have a level with a directional light on it set as mixed and my lighting parameters is :

    - Ambient GI set as Baked
    - Precomputed realtimeGI disabled
    - Directional mode set as Non directional
    - Auto build disabled

    I have build my lightmaps and everything work fine in the editor when i load my level but when i create an asset bundle by using :

    Code (CSharp):
    1. BuildPipeline.BuildAssetBundles (path, BuildAssetBundleOptions.None, target);
    When i download the asset bundle by using new WWW and then call Application.LoadLevel , the map is correctly loaded but i don't have my lightmaps anymore and the GI seem to be on because i can see the sun reflection on my map.

    *edit :
    Also , the lightmaps files are presents in my asset bundle

    but LightmapSnapshot.asset is at 0kb

    Someone have the same problem?

    Thank you.
     
    Last edited: Jun 29, 2015
  2. alexeyzakharov

    alexeyzakharov

    Joined:
    Jul 2, 2014
    Posts:
    507
    Do you have multiple scenes in a bundle?
    If not, this sounds like a bug. Could you please submit it.
     
  3. roka

    roka

    Joined:
    Sep 12, 2010
    Posts:
    598
    No, only one scene.

    I have solved the problem by changing the shader stripping to "manual" instead of "automatic" in edit/project settings/graphics.

    May help you to solve the problem in your next patch.
     
  4. alexeyzakharov

    alexeyzakharov

    Joined:
    Jul 2, 2014
    Posts:
    507
  5. KB73

    KB73

    Joined:
    Feb 7, 2013
    Posts:
    234
    I'm still having problems loading lightmaps from assetbundles.

    5.1.1p3

    Couple of questions

    1) Is the expectation for the lightmap atlas to be in the same bundle as the scene or do i just rely on the assetbundle dependency to pull it in? I want to not use the original source lightmap but a copy of it...so...
    2) What if we want to override this manually? I tried LightmapSettings.lightmap and point it to a new Texture2D but everything remains black. LightmapIndex is 0 and the offsets are correct. This should update at runtime correctly?
    3) This all works in Resources fine.
    4) Does the lightmapsnapshot need to be included in the assetbundle? I assume that was only for editor purposes?
    5) I'm procesing assetbundles by using the Map variant, i'm not sure if that is a problem or not as i specify the files to go in.

    thanks
     
  6. KB73

    KB73

    Joined:
    Feb 7, 2013
    Posts:
    234
    Ok having messed about all day and for the sake of other people running into this, it finally appears that you have to iterate over all the renderers once a scene is loaded and grab the sharedMaterials, simply re-assign the shader back to the material. I don't know if this is a bug or not, seems strange? On another note, i also hadn't put my shaders into the resources but Unity loaded some and not others, which was confusing.Even when i had done this, nothing occurred until i did the re-assignment. Now i have light maps but they are somewhat darker, so will see what pops up tomorrow :) Tried this on 5.1.1p3 and 5.2.1b1, was in iOS.
     
  7. Piflik

    Piflik

    Joined:
    Sep 11, 2011
    Posts:
    292
    The issue seems to be fixed in 5.2. Lihtmapped scenes can be loaded from AssetBundles without jumping through hoops.
     
  8. freestorm

    freestorm

    Joined:
    Sep 11, 2012
    Posts:
    2
    I still got this problem in 5.2.2. Any Official guy can help?
     
  9. freestorm

    freestorm

    Joined:
    Sep 11, 2012
    Posts:
    2
    I got it. The reason is BakedLightingmap Shader stripped by build, After i change the Graphic Settings to Manual,and check the shader,the problem solved.
     
  10. KB73

    KB73

    Joined:
    Feb 7, 2013
    Posts:
    234
    Good find, weird why it would strip when it is being used though, still some assetbundle dependency funkyness going on with duplicates etc
     
  11. Stardog

    Stardog

    Joined:
    Jun 28, 2010
    Posts:
    1,913
    I've set Shader Stripping to Manual, but I'm still getting black lightmaps. 5.4.0f3. Even checking all of the options doesn't work.

    I'm using the official AssetBundleManager package. It works fine in Simulation Mode in the editor, but not in the build.
     
    Last edited: Sep 13, 2016
  12. noahcharris

    noahcharris

    Joined:
    Mar 27, 2017
    Posts:
    1
    I am still experiencing this problem on 5.2.3, I just submitted a bug report
     
  13. kermani

    kermani

    Joined:
    Aug 13, 2013
    Posts:
    1
    In mobile game, when you load a model with non mobile shader (for example standard shader) from asset bundle, model lost it's lightmap. you can change your shader object to mobile type and it works well.
     
  14. AthosK

    AthosK

    Joined:
    Jan 20, 2013
    Posts:
    428
    Gonna necropost on this but does anyone found a proper solution?

    Atm, I downloaded the standard shader from the built-in package Unity has and when Instantiating a model that was loaded from asset bundle, I grab all renderers and force the downloaded shader on them. I haven't test yet what would happen if you build the bundles with that version of the shader on though but guessing it might be the same result might not be that much of a stretch
     
  15. orkungo

    orkungo

    Joined:
    May 3, 2014
    Posts:
    62
    One other necropost from me, anyone has a solution? It is stilling at the Unity 2017.1.0f3 for me, baked lightmaps are just not showing at the meshes with standard or mobile/diffuse shaders on mobile device..
     
  16. mr_zog

    mr_zog

    Joined:
    Jan 21, 2014
    Posts:
    165
    mzr likes this.
  17. amcakebread

    amcakebread

    Joined:
    Nov 8, 2016
    Posts:
    28
    awesome; three days of debugging before I stumbled across this thread!! WebGL baked lights in scene asset bundles were hosed until I set it to Baked Non-Directional only

    upload_2018-8-18_14-36-16.png
     
  18. manutoo

    manutoo

    Joined:
    Jul 13, 2010
    Posts:
    522
    Thanks to the people who have posted the Shader Stripping solution.

    I'll add : I had to rebuild my Asset Bundles to make this work (despite Unity knowing what kind of shaders it was needing when building them), not only the main build.