How I can change lightmaps at runtime?

I have an interior scene of a house, and i need to remove furniture with their generated lightmaps at runtime, and replace it with a set of lightmaps baked previously without furniture?

Thanks in advance.

There is another way to do this.
You can change lightmapData at runtime and it’s an interesting way that I use in one of my project.

You can do something like this :

The lightmapData array is the array which stack all the lightmaps used in your level and you can change them when you want.

For example if you need to change the sun orientation and you want that your lightmap change to you can reset this array with your new lightmaps.
All your lightmaps must be baked before btw.

When I want do this, I bake all the lightmaps that I need and I bake them with the same number of lightmaps to avoid all problems with offset and tilling on your meshes.

Indeed, if you baked your lightmaps and if the final lightmaps number is not the same you can have different offset and tilling for every mesh in your scene. So one lightmap will be correctly displayed whereas another one maybe not.

If you need more explanations, don’t hesitate I can give you more details :wink:

Edit : little script to do this simply ==> private void InitLightmaps( ){ LightmapData[] lightmapData = new Lightmap -

You could define several materials with different lightmaps and change them at runtime. Look at the example here: Renderer.material

Or you could change the texture for the shader. (You have to find the texture name inside the shader, e.g. "_LightMap".)

Here is the example: SetTexture

Try this:

using UnityEngine;

public class TransferLightmap : MonoBehaviour {

    public Renderer sourceObject;
    public Renderer targetObject;

    void Start () {
        targetObject.lightmapIndex = sourceObject.lightmapIndex;
        targetObject.lightmapScaleOffset = sourceObject.lightmapScaleOffset;

        targetObject.material.SetTexture("_LightMap", sourceObject.material.GetTexture("_LightMap"));