Lightmap issue when loading meshes from assetbundle

I’ve built an AssetBundle that contains

  • a prefab which has a couple of meshes
  • Lightmap textures
  • “loader” GameObject

The “loader” GameObject has a script that on Awake calls a function that

  • replaces the LightmapSettings.lightmaps array with the textures from the AssetBundle
  • instantiates the prefab

When the AssetBundle is loaded, the loader GameObject is instantiated. When I play, the meshes are visible but the lightmap is not correct. I’m not a strong graphics guy, but I think it looks like the UV coords are not correct (?).

I put [ExecuteInEditMode] on the loader script so I could write an editor script to instantiate the loader in the editor. When I do that, again the meshes are visible with the messed up lightmapping. But if I click any of the meshes in hierarchy, the lightmap instantly becomes correct for that mesh.

So what happens to the mesh in the editor when selected that causes the lightmap to be fixed? And how can I duplicate that at runtime?

Renderers have lightmapping coordinates that need to be stored and then restored when you load, check out:

http://docs.unity3d.com/ScriptReference/Renderer-lightmapTilingOffset.html
and

Thank you for the reply Wahooney. That was one of the first things I thought of and wrote a quickie script to dump those values from the renderers; sorry I didn’t mention that. The lightmapIndex and lightmapTilingOffset values are correct in the prefab.

Turns out its a third party component that is interfering with the the lightmap getting reset correctly. I tried a plain old Unity mesh & renderer, and that works fine with loader. So its off to their forum :slight_smile:

Hope you get your stuff sorted out :slight_smile:

Yep, we’re good :slight_smile: