Dual camera shadow problem

I’m currently making a fps, i had a problem that my weapon was cliping through walls, so i made another camera and i set it to render only the weapon on a different layer. It works, the weapon doesn’t clip through walls, but now i have a problem that shadows don’t interact with the weapon, because the objects are on different layers. Could someone help me fix this?

To get a better understanding of what i mean, see this. This persons solution is to duplicate every shadow casting object to the layer witch the gun is, and set the mesh filter to shadow cast only. I don’t use his solution, because i find it too messy.

I figured out a workable solution for my case:

  1. Make a parent game object that has the collider & rigid body

  2. Now add two nested children to it, each with the same Mesh + Mesh Renderer components

  3. Name one of them “View” and the other “Shadow Only”

  4. For the View object, use these settings:

75095-view-settings.png

  1. For the Shadow Only object, use these settings:

Shadow Only Settings

  1. Now apply all physics & animations to the parent object, and everything else should work naturally!

yes that is nice, but what if we have 30 weapons with differents hands, each weapon has his own scope etc… I have more than 100 objects…