NullReferenceException in ShadowCasterGroup2D

Hello!
I’ve encountered a problem after upgrading from Unity2020.3 to Unity2021.3.

I’m using some Composite Shadow Caster 2D components on objects with children that are sometimes casting shadows and sometimes not; it appears as if Unity wasn’t ready for the fact that the ShadowCasterGroup (known as Composite Shadow Caster 2D) didn’t have any actual shadow-casters in its hierarchy.

As a result all the sprites on the stage stopped rendering and the console was flooded with

UnityEngine.Rendering.Universal.ShadowCasterGroup2D.CacheValues () (at Library/PackageCache/com.unity.render-pipelines.universal@12.1.7/Runtime/2D/Shadows/ShadowCasterGroup2D.cs:15)```
(the stack keeps going, but the important part is in that line 15, I think.

```csharp
internal virtual void CacheValues()
{
     for (int i = 0; i < m_ShadowCasters.Count; i++)
          m_ShadowCasters[i].CacheValues();
}

If I add a simple

if (m_ShadowCasters != null)

everything works fine, until of course Unity reverts the file to the original package’s form (well unless I embed the whole package)

3 Likes

Is it still not fixed? It happens to me too…

Same issue here for me, Unity2020.3 to Unity2021.3, same error. Is there a recommended path to resolve this, apart from waiting for a fix from Unity?

2 Likes