Search Unity

Bug NullReferenceException in ShadowCasterGroup2D

Discussion in 'Universal Render Pipeline' started by scriptwelder, Jul 6, 2022.

  1. scriptwelder

    scriptwelder

    Joined:
    Feb 26, 2017
    Posts:
    3
    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

    NullReferenceException: Object reference not set to an instance of an object
    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.
    Code (CSharp):
    1. internal virtual void CacheValues()
    2. {
    3.      for (int i = 0; i < m_ShadowCasters.Count; i++)
    4.           m_ShadowCasters[i].CacheValues();
    5. }
    If I add a simple
    Code (CSharp):
    1. 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)
     
    Last edited: Jul 9, 2022
    KeeganKLM, greebo3 and Fymir27 like this.
  2. Jardar_Working_On_Seablip

    Jardar_Working_On_Seablip

    Joined:
    Jun 11, 2017
    Posts:
    4
    Is it still not fixed? It happens to me too..
     
  3. greebo3

    greebo3

    Joined:
    Mar 5, 2021
    Posts:
    4
    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?
     
    Sara_01 and KeeganKLM like this.