Why do the shadows sometimes disappear when the camera approaches?

Added on by Gustav Olsson.

This is caused by the built-in view frustum culling in Unity. Since the shadow volumes are extruded on the GPU and the view frustum culling happens on the CPU, Unity might choose to not render a shadow volume even though it will actually end up covering the view. (Notice that the shadow will only disappear if the shadow caster is outside the view frustum of the camera?)

To fix the problem, set the Bounds Margin to a large value (~1000) before setting up shadows using the Quick Shadow Setup dialog. The shadow mesh bounds are extended by this value and since the bounds are what determines the size of the mesh during view frustum culling, the mesh will not be culled (as easily).

Ideally, the Bounds Margin value should be set to the maximum length the shadow can reach from the shadow caster. Since this is difficult to determine in practice it's sufficient to just set it to a large value.