Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Broken Materials Not Accepting Lightmap Data

Discussion in 'General Graphics' started by ted-aronson, Jan 18, 2017.

  1. ted-aronson

    ted-aronson

    Joined:
    Dec 28, 2015
    Posts:
    8
    I just spent all day figuring this one out, and I'd like to document it for posterity (and Google), as well as ask for some more details.

    I'm working on a project where we additively load scenes from an asset bundle into an empty scene. The loaded scenes are lightmapped before we build asset bundles, using Baked GI and directional lightmaps. When we loaded the scenes in editor as if they were built into the player (using simulation mode in the official asset bundle manager package) the scene looked correct. However, when actually loaded from an asset bundle (either by building and running the player or by using the local asset server), the scene looked wrong. Some objects appeared to have proper lighting data, but some did not, and actually appeared to have no data. Stranger still was that all of the lightmaps appeared to get loaded correctly, and the relationship between each renderer and its lightmap seemed to be preserved correctly after loading.

    I eventually noticed that the material editor for one of the mis-lighted objects was displaying Forward Rendering Options, even though it was using the Standard shader with metallic setup (Forward Rendering Options should only appear with the Specular setup, I think). I tried switching the shader to Standard (Specular setup), and suddenly the object was lit correctly! And, when I switched it back to the metallic setup, the object stayed correctly lit.

    Looking at the .mat file, I found that switching back and forth had changed the m_Shader reference from something pointing at fileId: 46 and guid: 0000000000000f000000000000000000 to something pointing at fileId: 48000 and a more reasonable guid. My eventual solution was to do a text search for the broken m_Shader pointer and replace it with the new one from the working material.

    So aside from (apparently) fixing a broken file pointer, what did I actually do to fix this issue? Why did the material's shader appear as the Standard if it wasn't hooked up properly? If the file pointer to the shader was broken to begin with, why didn't the broken materials appear pink? And why did this only happen when the scene was loaded from a built asset bundle?
     
  2. areepen

    areepen

    Joined:
    Aug 28, 2017
    Posts:
    7
    I am plagued by the same issue when trying to use lightmaps in Asset Bundles.

    For some reason using the "Standard Shader (Specular setup)" will result in correctly applied lightmaps, while Materials using the "Standard Shader" will not use their associated light maps.

    Is this still a Bug in 2018.1 or am I missing something that would explain this behavior?