Lightmap not correctly assigned to terrain (solved)

Hi guys.

I’m having a problem with my lightmap on my terrain I load as a prefab from my assetbundle. When assigning back the lightmap information to the scene via code, I get the following result:

The lightmap is correctly loaded from the assetbundle into the lightmap settings:

My code for the terrain is:

            for (int i = 0; i < terrainList.Count; i++)
            {
                var aTerrain = terrainList[i];
                if (aTerrain != null)
                {
                    aTerrain.castShadows = false;
                    //aTerrain.gameObject.isStatic = true;

                    var aLightmapSetting = aTerrain.GetComponent<SNSLightmapSetting>();
                    if (aLightmapSetting != null)
                    {
                        aTerrain.lightmapIndex = aLightmapSetting.lightmapIndex;

                        while (aLightmapsDataList.Count <= aLightmapSetting.lightmapIndex)
                            aLightmapsDataList.Add(new LightmapData());

                        aLightmapsDataList[aTerrain.lightmapIndex].lightmapNear = aLightmapSetting.lightmapNear;
                        aLightmapsDataList[aTerrain.lightmapIndex].lightmapFar = aLightmapSetting.lightmapFar;
                    }
                }
            }

            LightmapSettings.lightmaps = aLightmapsDataList.ToArray();
            LightmapSettings.lightmapsMode = lightmapsMode;

I’m using the 5.2.0f3 editor version. Does anyone know what I might be doing wrong?

It is not enough to set the index. You also have to set the scale and offset.

@KEngelstoft

I see. It’s in since 5.2 I guess? Because before it was not possible to set those :slight_smile:

Thanks! Working now.