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?