2D shadow caster not working correctly...?

,

The shadow caster 2D only works on the highest light order. It just doesn’t cast any shadow from other light sources in the scene at all. Any workaround to this?

Hi there,
If this is the latest version of unity, I´m afraid there is no solution to this.
I have a project that I ended up for downgrading unity back to 2019 / 2020 because shadowCaster was not working properly.

got it, thanks for clarifying!
I thought this will be fixed with the new 2021 LTS, but it is not.
There is also a prefab override bug, going to wait for some patches then until it’s fixed.

Hi Rechronicle, MX-Pain, thanks for the info, cool game you are making. I wondering if there any reproduce step that I can follow?

Hi, can you clarify what you mean by this?

Shadows are rendered when
a) Shadows are enabled on the Light2D
b) Target Sorting Layers are the same for Light2D and Shadow Caster 2D

If the bug is sometime else entirely, please report it using these steps. Thanks.

Hi, this is the GIF to show it more clearly. Both Light2D settings are the same.
No matter how many Light2D I added on the scene, the ShadowCaster2D only works from 1 light source.
Unity 2021.3.0f1
8058878--1040765--Animation .gif

Hi Rechronicle, thanks for the info. I manage to reproduce this issue and will be following up this issue.

1 Like

I found a solution. Edit ShadowCaster2D.cs at line 121 to always return true. This fixed the issue for me!

1 Like

Hello!
I ran into this bug also and it was quite frustrating, so I did some experiments before submitting a bug report.
If it can help to solve it, here is a video of the differents parts of the issue: Bug Unity 2021.mp4 - Google Drive

As shown in the video, several strange things happen around this bug:

  • If I move the second light closer to the shadow caster, the bug stops as soon as the lamp touches the caster.
  • If I zoom in enough in the scene, the bug disappears as soon as the secondary lamp is not visible anymore.
  • If I change the Light Order, the bug disappears as soon as the order of the second light is lower than the order of the first.
  • If I add another shadow caster on the second lamp, the bug disappears.

This bug happens with Unity 2021.3.3f1 (Universal RP 12.1.6).
I tried to reproduce this bug in the Unity 2022.1.1f1 version (Universal RP 13.1.8), and it seemed to be fixed (with the same conditions). But I finally managed to reproduce it, by putting a second shadow caster near the second light, and when the two lights are not on the same Blend Style.

The solution proposed by @Ellbell is working, but I guess it’s not good for performances. And speaking about performances… There seems to be some serious memory leaks in the shadow system, because as I deactivate/reactive shadow casters in my game, the performances are getting worse and worse, even with just one light. And as soon as I disable shadows from this light, everything becomes smooth again.
According to the profiler, the problem seems to happen here:
8158781--1060526--upload_2022-5-26_15-28-29.png

Anyway, because of the bug and performance issues, the 2D shadows are currently impossible to use in a game imo, so I switched to the Smart lighting 2D from the asset store. But I hope the URP system will be usable again in the future :slight_smile:

Correction. It works on the light with the highest Light Order with shadows turned on and any lights within the Outer Radius of the light with the highest Light Order with shadows turned on. As a result I created a simple workaround for now.

I am using 2021.3.3f1 and this is still an issue.

  • Create a Light 2D

  • Place the light in the center of the scene

  • Set the Light Order to 999

  • Increase the light’s Outer Radius so it covers your entire scene

  • Set its Intensity to 0

  • Enable shadows and set Strength to 1

  • Place your “real” lights in the scene using any Light Order < 999; typical numbers like 0, 1, 2, 3… use a “normal” radius, intensity, and so forth.

  • Viola you have working shadows with as many lights as you want.

However, I have no idea how this impacts performance. I have not measured, so don’t beat me up. On my laptop I am not noticing any difference for all that is worth (not much I am sure).

5 Likes

Hi GabrielWink PharmacyBrain Ellbell, thank you for the work around, and appreciate your help :slight_smile:

Issue is still happening in 2021.3.12f1 (URP 12.1.7). Can’t seem to edit the script personally. When I save it just rewrites what was initially there. Also, is line 121 to return of the IsLit() function?

@PharmacyBrain You are the king of workarounds! I have been working with Unity since May 2022 to get this issue resolved. I have had multiple calls with their developer relations team and have watched numerous bug reports get kicked around, rejected, re-implemented and now… finally released (!!10 months later!!), only to my dismay, not address the issue even remotely.

My sincere thanks for posting this workaround. It makes me cringe to think I might actually have to ship something like this, but Unity has really backed us all into a corner here with their rushed code and inability to release real fixes.

3 Likes

Thank you for this workaround! It works brilliantly (light pun intended), and I, too, have not noticed any performance degredation.

1 Like


Somehow the light is managing to kinda go past the shadow caster. This only happens at certain positions and angles


Yeap I still have the problem, it’s seen to be related to shadow caster attached to transform wich the scale are changed.

I have made a simple scene from scratch:

By changind the scale of inner shadow caster :
9780099--1402377--upload_2024-4-19_9-27-4.png

I can make the shadow bug depending of the position of the light if the light is very close :

@Drivinmecoco , check if your wall used a special scale and if putting it to (1,1,1) change the bug.

Thanks for you help.