Lightmap baking for modular scene with 50 000 objects

Hello everyone!

I’m currently creating a big city, with around 8000 instances of 60 different buildings.
These building prefabs are each made of 3 - 10 models. I only have 32 of those models in total, so the workflow has been very modular so far. Now I want to bake a lightmap for these buildings, but since the light is baked on each and every one of the building parts, this seems, well… impossible. I’d have a lightmap for every model out of 50k models.

Now here’s my question:
Is there a way in unity to bake lightmaps for prefabs instead of for every object this prefab is made of?
If not, what are my options here?

Thanks in advance!

There’s no way to selectively just bake a prefab and instantiate it.
What you may be able to do is bake one instance in a separate scene, additively load it and then fix up all other instances with the lightmap parameters of the added in object with a custom script.

Hello Jan-Pieter.

There is a trick using a script that can help, however it comes with some drawbacks, please read them carefully before considering using the script :).

The main drawback is that if you bake a prefab and reuse its baked lighting, it’s gonna be a straight copy paste of its lighting. For instance, if the prefab is not shadowed by anything in the prefab mode, you are not gonna get any shadow when you use that prefab in your scene. This can be ok in some scenarios, but it’s a pretty limited use case.
Other drawback is that the lighting setup in the prefab as to match the lighting of your scene to make the baked lighting consistent when you reuse that said prefab in the scene. You will have to manually synchronize lighting between you prefab baking mode and your scene. If it’s just a sunlight (directionnal) that could be ok.

If you think this trick is good for your use case you can have a look at this post:

Hope that helps,

Cheers !