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

Lightmaps ignored at scene loaded from AssetBundle

Discussion in 'Asset Bundles' started by fgpinilla, Apr 30, 2019.

  1. fgpinilla

    fgpinilla

    Joined:
    Apr 11, 2016
    Posts:
    6
    Hello!

    We're having some troubles with the illumination loading scenes both in runtime and editor mode, in Unity 2018.3.12f1.

    When we load the scene included in the build (from the scenes in build list) everything goes well, all the lights work as expected, realtime and baked lightmaps.

    The problem comes at the moment when we load the scene from an assetbundle. In this case, the realtime light works as expected, but the baked lightmaps are not working.

    Is there any workaround for this?

    Thank you so much!

    office.png

    livingroom.png
     
  2. Ryanc_unity

    Ryanc_unity

    Unity Technologies

    Joined:
    Jul 22, 2015
    Posts:
    332
    This is most likely shader variant not being compiled into the asset bundle with the correct flags for lighting. So my recommendation since you are on 2018.3 is to install and use Scriptable Build Pipeline package to build your asset bundles. Getting started: https://docs.google.com/document/d/1uuiEDV7WqpHEylzE4GQwOztCttrwPu6ak0kfELz6ilc

    An alternative is to install and use the Addressables package which makes working with asset bundles so much easier. Documentation: https://docs.unity3d.com/Packages/com.unity.addressables@0.7/manual/index.html
     
  3. fgpinilla

    fgpinilla

    Joined:
    Apr 11, 2016
    Posts:
    6
    Hi @Ryanc_unity,

    Thank you for your support!

    We cannot go through the Addressables approach, because we are too late in the development process and also we need to support consoles builds, so...

    We're trying to build our AssetBundles with the new Scriptable Build Pipeline, but we're obtaining a 'System out of memory' exception in the process (during the dependencies calculation state).

    This is an already fixed bug for the old Build Pipeline in 2018.3.11f1:
    Build Pipeline: Added a call to clean up high memory usage in BuildPipeline.BuildAssetBundles to avoid a crash due to out of memory. (1124274, 1129898)

    So, could the Scriptable Build Pipeline being upgraded to include this fix, or it is something new that needs to be investigated?

    In any case, the shader variant not being compiled with the correct lighting flags issue, is something that could be fixed in the old Build Pipeline?

    Thank you again!
     
  4. fgpinilla

    fgpinilla

    Joined:
    Apr 11, 2016
    Posts:
    6
    We have also made some tests regarding Lightmap Modes in Shader Stripping, but we still get the same results, the not expected light when we load the scene from an AssetBundle and the light working as expected when the scene is included in the scenes in build from the Build Settings.

    We have checked the Automatic mode, the Custom with checks from 'Import From Current Scene' button and the Custom 'All checks'.

    Is there any other test we could make, beyond waiting for a possible fix in this issue or the fix for the 'out of memory' crash?
     
  5. ShadowLairGames

    ShadowLairGames

    Joined:
    Jan 17, 2019
    Posts:
    45
    @Ryanc_unity
    Is there any update on this on the Asset Bundle side of things?

    I'm on 2019.2.0f1, and it looks like no lightmaps are being loaded for my bundled scenes at all.
    (Everything black are renderers that were static baked, the lit objects are realtime lit).
    upload_2019-12-31_2-14-16.png

    This project is about a month out from completion and I'd really prefer not to go to any extreme solutions such as replacing our asset management system to use Addressables.
    Please tell me there's a solution for this by now?
     
  6. ShadowLairGames

    ShadowLairGames

    Joined:
    Jan 17, 2019
    Posts:
    45
    So I ended up converting the Asset Bundle Browser to use the SBP instead of the legacy pipeline, which was straight forward enough, but then spent a whole day struggling to find out why everything is now breaking in my project, with null reference exceptions and missing references in the inspector all over the place after loading assets from the new bundles.

    From what I can tell, the SBP can't seem to serialize reference fields that are using an abstract type.
    The simplest form of this I ran into are fields I had in some of my bundled objects that were defined as:
    [SerializeField]
    private TMP_Text m_SomeLabel;

    TMP_Text is an abstract class used in TextMeshPro. Both the TextMeshProUGUI (UI text) and TextMeshPro (3D text) components inherit it, and when explicitly stating one of those in the type of the field instead of TMP_Text, then the reference persists, but if the field type is the abstract TMP_Text type, then when I load the object from the bundle the reference would be null.

    This is kind of a big deal.
     
  7. Alex_Heizenrader

    Alex_Heizenrader

    Joined:
    May 16, 2019
    Posts:
    89
    Any resolution in the end with this?

    I don't get why the lighting data asset is not loading with a scene from an assetbundle.

    What's more, if I load the scene on its own from an assetbundle, the lightmaps are applied, but if I do additive loading then they are gone. 2019.2.9f1

    UPDATE: It was the original scene having checked auto-lighting (not the one additively loaded), once I took that off everything is fine (even the though it doesn't show the lighting data asset applied, I believe its working since even light probes work)
     
    Last edited: Apr 19, 2020
  8. LaurynasLubys

    LaurynasLubys

    Joined:
    Mar 7, 2012
    Posts:
    80
    Hey, where is this " auto-lighting" function located? I am having the same issue.
     
  9. Alex_Heizenrader

    Alex_Heizenrader

    Joined:
    May 16, 2019
    Posts:
    89
    upload_2020-7-23_15-15-54.png
     
  10. LaurynasLubys

    LaurynasLubys

    Joined:
    Mar 7, 2012
    Posts:
    80
    Oh, that will just re-bake the scene in my case. Thanks anyway.
     
  11. Alex_Heizenrader

    Alex_Heizenrader

    Joined:
    May 16, 2019
    Posts:
    89
    That's what I meant with auto-lighting, this should not be checked.
     
  12. MatrixInception

    MatrixInception

    Joined:
    Oct 17, 2016
    Posts:
    9
    Could you please provide more guidance on how to incorporate lightmaps into AssetBundle load using the Scriptable Build Pipeline?
     
    AndyRat likes this.
  13. MatrixInception

    MatrixInception

    Joined:
    Oct 17, 2016
    Posts:
    9
    Hello everyone, I think I have figured out how to load the lightmap of a scene assetbundle in Unity 2019.4:
    using AssetBundle Browser:
    Step 1: label the lightmap assets into a separate assetbundle from the scene assetbundle and build them as assetbundles.
    in your script:
    Step 2: load the lightmap assetbundle first in a corountine with yield return new WaitForSeconds(0.5f);
    Step 3: load manifest dependencies for the scene assetbundle
    Step 4: load the scene from the scene assetbundle.