Lightmaps Addressables on selected objects

Hi,

I’m working on optimizing a game by disabling prebaked lightmaps on Awake to reduce initial memory usage, only loading them when necessary for specific visible parts of the scene. I’d like to avoid creating separate baked prefabs for each part of the environment and instead manage lightmaps by fetching them based on their indexes.

Here’s the approach I’ve taken so far:

  1. Baked the scene.
  2. Converted the lightmaps into addressables.
  3. On Awake, I:
  • Created a dictionary that stores the index of all static objects with lightmaps.
  • Set all objects’ renderer lightmap indexes to -1.
  • Planned to fetch the required addressable based on each object’s original lightmap index.
  • Updated the index on objects to restore their original lightmap index when needed.

The idea is to retrieve lightmap indexes on Awake, store them in a dictionary, and load the lightmaps from addressables based on these indexes when required.

However, I’m facing an issue with addressables; it seems like all lightmaps load automatically on Awake/Start, likely due to LightingDataAssets, as they appear in the memory profiler on debug.

Could you provide guidance on how to selectively load and release specific lightmaps from addressables only when needed during runtime?

Lightmaps are indeed loaded automatically on scene load. There isn’t any supported way to disable that. You might be able to hack the behavior by deleting the LightingDataAsset associated with your scene, and managing the data entirely on your own. You can control the list of loaded lightmaps from script though, using Unity - Scripting API: LightmapSettings.lightmaps. Can’t really think of anything else

Thank you for the reply.

Can you elaborate a bit more on how this can be done?

Its not possible to duplicate the LightingDataAsset and just assign 1x1 black textures and then just update the array on runtime?

The LightingDataAsset is kind of a black box for which we don’t offer ways to edit it but if you’re willing to get your hands greasy I can offer a workaround to prevent lightmaps from being loaded:

You can break the link between the LightingDataAsset and the lightmap textures it references by editing their associated .meta files with a text editor and change the guid entry to some other value (you can find online GUID generators such as this one to generate the new values, just untick the hyphens checkbox to match Unity’s guid format). You’ll see the lightmaps instantly disappear in the Editor scene view as you save your modified .meta files.
You have to do that manipulation for all the lightmap textures that the LightingDataAsset references (and directional and shadowmask if you bake them too) and redo it every time you regenerate your lighting. Be careful to not modify any other .meta files.

In any case, if you want to lobby for something more robust, you can submit a feature request here: https://portal.productboard.com/unity/1-unity-platform-rendering-visual-effects/c/561-didn-t-find-what-you-were-looking-for

1 Like