PrefabLightmapping icon indicating copy to clipboard operation
PrefabLightmapping copied to clipboard

"Index was outside the bounds of the array"

Open viv-01 opened this issue 3 years ago • 8 comments

I'm getting the following error, Can you advise?

IndexOutOfRangeException: Index was outside the bounds of the array. PrefabLightmapData.GenerateLightmapInfo (UnityEngine.GameObject root, System.Collections.Generic.List1[T] rendererInfos, System.Collections.Generic.List1[T] lightmaps, System.Collections.Generic.List1[T] lightmapsDir, System.Collections.Generic.List1[T] shadowMasks, System.Collections.Generic.List`1[T] lightsInfo) (at Assets/Scripts/PrefabLightmapData.cs:245) PrefabLightmapData.GenerateLightmapInfo () (at Assets/Scripts/PrefabLightmapData.cs:182)

viv-01 avatar Jun 11 '21 08:06 viv-01

Something is off, I'd recommend removing the script and adding it again to the prefab and rebake

Ayfel avatar Jun 11 '21 12:06 Ayfel

Hi bro! A value of 0xFFFE is internally used for objects that have their scale in lightmap set to 0; they affect lightmaps, but don't have a lightmap assigned themselves.

https://docs.unity3d.com/ScriptReference/Renderer-lightmapIndex.html

1ibrium avatar Jul 06 '21 17:07 1ibrium

Hi bro! A value of 0xFFFE is internally used for objects that have their scale in lightmap set to 0; they affect lightmaps, but don't have a lightmap assigned themselves.

https://docs.unity3d.com/ScriptReference/Renderer-lightmapIndex.html

I am not following, what is this in reference to?

Ayfel avatar Jul 06 '21 18:07 Ayfel

I fixed this issue by follow this reference, This issue triggered by "scale in lightmap set to 0"

1ibrium avatar Jul 20 '21 03:07 1ibrium

I fixed this issue by follow this reference, This issue triggered by "scale in lightmap set to 0"

Feel free to make a pull request or give us a snipet to include : )

Ayfel avatar Jul 20 '21 14:07 Ayfel

OK, as soon as possible

1ibrium avatar Jul 21 '21 16:07 1ibrium

                if (renderer.lightmapScaleOffset != Vector4.zero)
                {
                    //1ibrium's mod : https://docs.unity3d.com/ScriptReference/Renderer-lightmapIndex.html
                    if(renderer.lightmapIndex < 0 || renderer.lightmapIndex == 0xFFFE) continue;
                    info.lightmapOffsetScale = renderer.lightmapScaleOffset;
                    Texture2D lightmap    = LightmapSettings.lightmaps[renderer.lightmapIndex].lightmapColor;
                    Texture2D lightmapDir = LightmapSettings.lightmaps[renderer.lightmapIndex].lightmapDir;
                    Texture2D shadowMask  = LightmapSettings.lightmaps[renderer.lightmapIndex].shadowMask;
                    info.lightmapIndex = lightmaps.IndexOf(lightmap);
                    if (info.lightmapIndex == -1)
                    {
                        info.lightmapIndex = lightmaps.Count;
                        lightmaps.Add(lightmap);
                        lightmapsDir.Add(lightmapDir);
                        shadowMasks.Add(shadowMask);
                    }

                    rendererInfos.Add(info);
                }

1ibrium avatar Jul 21 '21 16:07 1ibrium

Thanks! I'll push it

Ayfel avatar Jul 21 '21 16:07 Ayfel