Lightmap UVs missing in play mode

I’m having a problem where the lightmap information is correctly assigned to the objects in edit mode, but in play mod it loses the lightmap uv’s for all the objects except the terrain, how can I solve this problem?

Also, the project uses a script (below) that changes the LightingDataAsset during play, how does this affect the light map uv?

void SetInitialEnvironment()
{
    RenderSettings.skybox = isDay ? daySkybox : nightSkybox;
    Lightmapping.lightingDataAsset = isDay ? lightingDataDay : lightingDataNight;
    dayLight.enabled = isDay;
    nightLight.enabled = !isDay;
    RenderSettings.sun = isDay ? dayLight : nightLight;

    foreach (GameObject obj in dayObjects)
    {
        obj.SetActive(isDay);
    }
    foreach (GameObject obj in nightObjects)
    {
        obj.SetActive(!isDay);
    }

    if (isDay)
    {
        nightSound.Stop();
        daySound.Play();
    }
    else
    {
        daySound.Stop();
        nightSound.Play();
    }
    DynamicGI.UpdateEnvironment();
}

Thanks in advance for any help.

Lightmapping.lightingDataAsset is editor-only API. You won’t be able to use it at runtime. If you remove the line that sets it, does the issue still happen?

I removed the line and it does solved the UVs missing problem.
But there is still need a function to change lightmaps at runtime, maybe I will need to try other ways to achieve that.
May I ask any hint to reach that?
Thanks a lot :slight_smile:

You can change the lightmap currently used by a renderer at runtime using these APIs:

You can change the list of currently loaded lightmaps using this:

lightmapIndex is an index into that array^^

You’ll have to manually keep track of the different desired values for these properties and change them at runtime. If both sets of lightmaps have the same layout, just changing LightmapSettings.lightmaps should be sufficient.

There are some community made tools floating around to automate this, but unfortunately nothing official.

1 Like