Removing unused lightmaps after level unload

I’m building a large explorable area for a game I’m working on, and I’ve got small sub-level chunks that load in and out using LoadLevelAdditive and Destroy. But I noticed that when a chunk gets destroyed, its associated lightmaps remain in the index, and if that chunk gets re-loaded again (like if the player were to turn around and go back), it loads the lightmaps for that scene into the index a second (or third, or fourth, etc…) time.

Is there any way to run a script to remove associated lightmaps from the index during runtime, something that’d be run before the Destroy, to avoid this from happening?

To get rid of all the lightmaps in the array you can use:

		LightmapSettings.lightmaps = new LightmapData[0];
		Resources.UnloadUnusedAssets();

If you wanted to keep a certain base set of Lightmaps, you could probably make a copy of LightmapSettings.lightmaps before you load any extra areas. Then assign that array whenever you need to.

LightmapSettings.lightmaps = null;

my solution