• RuntimesUnity
  • Problem with Shadow Caster 2D and Spines with meshes.

We are making a heavy use in our project of 2D lights and Shadow Caster 2D on URP, and I noticed that when I have a Spine with a mesh, Shadow Caster 2D uses that mesh as the collider/mask for projecting shadows, which produces really nasty results.
For instance I have this tree in Spine with its mesh:

But in-game when I focus my light on the tree, the shadow it projects looks wrong because it seems to be using somehow the contours of the Spine mesh as well as the Shadow Caster 2D to project the shadow.


The Shadow Caster 2D collider (in white) looks like this:

And this is the Shadow Caster 2D window dialog I'm using:

Do you know why this could be happening? With normal sprites (not Spines) shadows work correctly.

We are using the latest versions of the Spine runtimes and URP. Unity 6.1.2f1.

Thank you very much in advance!

Related Discussions
...

@Kikekun Unfortunately it seems that the MeshRenderer's complete mesh is blocking the shadow to simulate the "no self-shadowing" behaviour. If at the Shadow Caster 2D under Casting Option you select Cast And Self Shadow instead of just Cast Shadow, the whole area is properly shadowed. This does not really resolve your problem if you want the tree skeleton object to not be self-shadowed though. Unfortunately this does not seem to be a shader issue (using a non-Spine URP 2D shader causes the same incorrect behaviour) but only related to using a MeshRenderer instead of the Sprite internal renderer.

The best workaround for this problem seems would be to add one Shadow Caster 2D component at the skeleton GameObject with Casting Source set to None to disable the incorrect skeleton MeshRenderer's shadow, and then add a second Shadow Caster 2D child (or sibling) GameObject with mode Cast Shadow and your desired shadow shape.

In general, the MeshRenderer's mesh geometry is used with Shadow Caster 2D instead of respecting texture-alpha transparency, as described in this forum posting. I assume you're aware of that, just mentioning for sake of completeness.

  • Kikekun ответили на это сообщение.

    Harald Thank you very much, Harald!
    And I apologize I asked the same question to you 4 years ago 😅My fish memory is back at it again, it seems...hahaha. I honestly did not remember that one.

    @Kikekun Oh, I didn't notice it was you in this posting! 😃
    No need to apologize, I also forget a lot of code-related things that were 4 years ago. 🙂