Shadow Caster 2D throws NullReferenceException when set to ShapeEditor

I could reproduce this in all Unity 6 versions. Not in 2022.

Steps to reproduce.

  • create a new 2d project (URP)
  • add some sprites to the scene.
  • create a light
  • add a shadow caster 2d component to any of the sprites
  • set it to shape editor
  • watch this error msg getting spammed every frame.
NullReferenceException: Object reference not set to an instance of an object
UnityEditor.Rendering.Universal.ShadowShape2DProvider_ProperyDrawer.ProcessChildren (UnityEditor.SerializedProperty parentProperty, UnityEditor.Rendering.Universal.ShadowShape2DProvider_ProperyDrawer+ProcessChild onProcessChild) (at ./Library/PackageCache/com.unity.render-pipelines.universal@24527717fb47/Editor/2D/Shadows/ShadowProvider/ShadowShape2DProvider_ProperyDrawer.cs:30)
UnityEditor.Rendering.Universal.ShadowShape2DProvider_ProperyDrawer.GetPropertyHeight (UnityEditor.SerializedProperty property, UnityEngine.GUIContent label) (at ./Library/PackageCache/com.unity.render-pipelines.universal@24527717fb47/Editor/2D/Shadows/ShadowProvider/ShadowShape2DProvider_ProperyDrawer.cs:68)
UnityEditor.PropertyDrawer.GetPropertyHeightSafe (UnityEditor.SerializedProperty property, UnityEngine.GUIContent label) (at <2c15cbbf1b184f238c5db654082b15fa>:0)
UnityEditor.PropertyHandler.GetHeight (UnityEditor.SerializedProperty property, UnityEngine.GUIContent label, System.Boolean includeChildren) (at <2c15cbbf1b184f238c5db654082b15fa>:0)
UnityEditor.PropertyHandler.OnGUILayout (UnityEditor.SerializedProperty property, UnityEngine.GUIContent label, System.Boolean includeChildren, UnityEngine.GUILayoutOption[] options) (at <2c15cbbf1b184f238c5db654082b15fa>:0)
UnityEditor.EditorGUILayout.PropertyField (UnityEditor.SerializedProperty property, UnityEngine.GUIContent label, System.Boolean includeChildren, UnityEngine.GUILayoutOption[] options) (at <2c15cbbf1b184f238c5db654082b15fa>:0)
UnityEditor.Rendering.Universal.ShadowCaster2DEditor.OnInspectorGUI () (at ./Library/PackageCache/com.unity.render-pipelines.universal@24527717fb47/Editor/2D/Shadows/ShadowCaster2DEditor.cs:134)
UnityEditor.UIElements.InspectorElement+<>c__DisplayClass79_0.<CreateInspectorElementUsingIMGUI>b__0 () (at <2c15cbbf1b184f238c5db654082b15fa>:0)
UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr, Boolean&)

Bump.
am i the only one experiencing this?
i tested it and i could reproduce it with 6.2 beta too.

Anybody?

I would suggest reporting a bug, posting on the forums will only help you if other devs are experiencing the same issue.

To actually get it fixed, it needs to be reproduced and verified so a bug report is required.

Thanks.

i’m experiencing the same error… no idea whats happening

Same thing for me. 6.0 LTS
I migrated a project with a TON of shadow casters with shape edits. They are the source of the spammed errors in the console same as OP.

Update:
I tried the following with no success

  • Delete library and recreate
  • Reinstall URP
  • Reimport Assets
  • Delete the shadow caster 2D and make a new one

I noticed this issue for me was only related to the editor so far that I can tell. The shadows in the game seem to be working. For me, if I collapse the shadow caster 2D element in the inspector the errors stop - I believe its literally just trying to draw some field in the inspector and issuing an error.

Having the same problem. I didn’t realize it was because of “Shape Editor” set as the “Casting Source”, thanks for pointing that out.

Double-clicking on the error takes me to the ShadowShape2DProvider_ProperyDrawer class and specifically line 30:

Type parentType = parentObj.GetType();

I’ve had this happen in two projects: one where I created a new 2D URP project and added a variety of new assets from an old project (just copy-pasting them into the Assets folder basically), and one where I just added a few sprites.

Yup, I discovered the same thing.

Yeah I did that too. :saluting_face:

You might find you’re the only person to actually report it.

If you have the incident number, please provide it to me and I’ll pass it along for you to the team.

Thanks.

I’m very sorry this is so late, but I overlooked the email notification of your message.

I’m not currently encountering about it because I’m working in some other areas, but I’m probably come across it again eventually.

My bug report was closed due to it being a duplicate. IN-106786

Last I read, “Resolution Notes: null Duplicate of another internal issue: UUM-97647: ShadowCaster2D Throws NullReferenceException when using ShapeEditor casting source

Izabelė G said, “The fix is actively worked on and should be available from 6000.0.53f1, 6000.1.11f1 and 6000.2.0a9 Editor versions.”

oh btw i already did report the bug.

So I guess that was fixed?

nope. have the latest packages still the same error.
maybe it is fixed somewhere but i have no idea how to access that…

Did you report that in your case that it didn’t fix the case?

Note that I’m not the dev involved in this, I know nothing about it unfortunately.