Shadow Caster 2D with Sprite Renderer

Is it possible to have a sprite cast it's own shadow instead of having to edit the shape for each frame?

Above you can see how I set up the component in my Player (it's in the sprite object, which has the Sprite Renderer and the Animator) but it doesn't cast any shadow.

The weird thing is that if I use Casts Shadows it does cast a shadow but I have to change the shape for each animation frame (which is not something I'm willing to do).

Am I missing something or is this a bug? (I'm using Unity version 2022.3.5f)

Hey @GebF92 , thank you for your question!

So due to popular requests, we actually added that support from 23.1 onwards. So if you added a Shadow Caster 2D to a Sprite Renderer that has an Animator, let's say for a flipbook animation, by default your Casting Source will be set to the Sprite Renderer.

We then grab the Custom Outline information from the Sprite Editor so you get animated shadows out of the box. Meaning, when your character runs or jumps, and the Custom Outline updates accordingly to your character silhouette, so does your character's shadows.

Casting Source: Sprite Renderer
9219735--1286799--Casting Source.png

Also, there's a quick and convenient way to trim your edges via the Trim Edge property which essentially allows you to contract your Custom Outlines to control the size of your shadow conveniently without having to do so one-by-one in the Sprite Editor's Custom Outline module.

Trim Edge
9219735--1286802--Trim Edge.png

9219735--1286805--Trim Edge Demo.png


Hi @Xiangting_Su, I just wanted clarification on something.

Animated shadows only seems to work about half the time I go into play mode. The other half of the time, it is static, holding the same shape as the original sprite it had before entering play and never changing from that.

The only way to get it to work consistently, i've found, is to either add the Shadow Caster 2D component to my desired gameobject after play mode is started and running, or to change one of the values on a preexisting Shadow Caster 2D component when play mode has started.

Is there something we should be doing for the animated shadows feature to work consistently when going into play mode?

Hi @suxiangting ,I use the version 2023.2.0f and I notice that when the shadow caster cover the source of freeform light, the light will be completely shaded. The old version(2022.3) doesn't happen that(when shadow caster cover the light the shadow will disappear). This made the light in the game weird.How can I solve this?