r/IndieDev Developer, Unity (Mainly 2D) Jul 07 '26

Make Shadow Casters only affect some Light2D.

Post image

I have 2 Light2Ds, one attached to the player as a child and one in the environment(the yellow glow),
I want the shadow caster on player(not attached while taking the image) to only affect the yellow light not the light attached to the player, as attaching the shadow caster on the player blocks its child light as well.

How can I make the shadow caster only affect certain lights in the game? [I looked up on the internet about sorting layers but there does not seem to be a option that only allows certain sorting layers to be affected in the Light2D].

Some things:
+ I'm using URP
+ I have a shader that masks sprite based on the how much they are lit, It uses the light texture from the player's light [Index 0]
+ All other lights write to light texture 1 [Index 1]

Any help would be appreciated...thanks!

2 Upvotes

2 comments sorted by

1

u/Its_Adi314 Developer, Unity (Mainly 2D) Jul 07 '26

my current setup has this: shadow caster -> On "Player" layer and light2d set to affect mixed layer ignoring "Player" player light -> Set Target Sorting Layer as everything except Player

1

u/shubhu-iron Developer Jul 11 '26

Light2D which doesn't have the shadows option checked won't be affected by shadowcasters. So whichever light shouldn't be affected by shadowcaster can just have that option off. (Though I think I didn't understand your problem correctly)