In my Unity project, the player sees the action from a bird's eye view. If he walks into a building, the roof should become invisible. The problem now is that the lighting shouldn't change, which means that the sun and other light sources that didn't penetrate through the roof before shouldn't do the same with the transparent roof. This means that the interior remains illuminated only by the interior lighting, even if there is no longer a roof.

enter image description here

The blue areas in the image should simulate the shadows cast by the sunlight source. Note: This does not fully describe the problem mentioned, since it is not only about the shadows, but also about the illumination of the interior. (But I didn't know how to draw this...😓)

How can I achieve this?


Through @DMGregory's answer, I set the MeshRenderer of all roof objects to "OnlyCastShadow" via script. However, this doesn't seem to work in play mode. It looks as if the sun's rays are penetrating the building again outside of a certain area.

Gif Link

What could be the reason?

  • 1
    \$\begingroup\$ Have you looked into setting the roof as a shadow caster only, or creating a light-blocking object that's set as a shadow caster only? \$\endgroup\$
    – DMGregory
    Commented Dec 10, 2022 at 3:22
  • \$\begingroup\$ Oh, it really is that simple... Thank you! ❤️ \$\endgroup\$ Commented Dec 10, 2022 at 12:00
  • 1
    \$\begingroup\$ If that solved your problem, can you port an Answer showing how you applied it? \$\endgroup\$
    – DMGregory
    Commented Dec 10, 2022 at 12:45
  • \$\begingroup\$ I'll definitely do that, but it doesn't seem to solve the problem 100% yet because the result is incorrect. The interior areas are not displayed correctly in play mode. It looks as if outside of a certain area, the rays of light reappear from the outside. I included that as an edit in the main question. \$\endgroup\$ Commented Dec 10, 2022 at 13:59
  • 1
    \$\begingroup\$ And using something like from this answer? gamedev.stackexchange.com/questions/152824/… Having a full roof for making the shadows correctly but hide it when player comes close \$\endgroup\$
    – Zibelas
    Commented Dec 10, 2022 at 16:32

1 Answer 1


I think I could fix the problem now. In essence, @DMGregory's answer helped by setting the roofs to "MeshRenderer -> Cast Shadows -> "Shadow only".

Then there was the problem with the incorrect and circular shadows. This can be solved in two ways.

  1. In ProjectSettings -> Quality -> Set Shadow Projection to "Close Fit".
  2. Alternatively, it can remain set to "Stable Fit", but then the camera's far clipping plane must be set to a much higher value until the sector of the circle is no longer visible.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .