LoadLevelAdditiveAsync + Lightmap index

Hi guys,

I have 2 Levels. A level is a group of scene.
A level is loaded using LoadLevelAdditiveAsync() for each scene in the level.
When one level is completely loaded, I unload the previous level by using Destroy() on the Root GameObject of each scene in the level.

Most scenes have lightmap generated by the tools in unity (Window > lightmapping).

When I launch the game, level 1 is loaded, everything is fine. LightmapSettings.lightmaps.Length equals 11 and if I look at renderer.lightmapIndex for an object it says 6.
I load level 2, each scenes of level 1 are destroyed (they do not appears in the Hierarchy anymore). LightmapSettings.lightmaps.Length equals 9x wich is ok, LightmapSettings.lightmaps should now contains all my lightmap.

The problem is when I load level 1 again. Level 2 is destroyed fine (again, no scene from the level 2 appears in the Hierarchy).
But LightmapSettings.lightmaps.Length is now equals 101 and my object wich had a lightmapIndex of 6 has now a lightmapIndex of 96.

To put it simply, each time I load a level, the LightmapSettings.lightmaps array is growing and when the length reach 255, my objects have a lightmapIndex of -1.

I tried to clear the Lightmap array but it kinda broke the lightmapIndex of my objects.

I don’t know if I just unload my level incorrectly or I should just manage the Lightmap array and the lightmapIndex of all my objects manually (hopefully not).

I searched for a similar problem and the closer I found was this post but there’s no solution.


LightmapSettings.lightmaps = new LightmapData[0];