- My GameObject(s) do not show any shadows when I am using either baked shadows or real-time shadows in my scene.
The most common reasons for this issue are:
- The Shadows aren't activated on the Quality settings.
- The Culling Mask on your Light is not pointing to any Layer.
- The Strength of the Realtime Shadows on the Light is too low to be visible.
- The Render Mode on the Light is not set correctly.
- The Shadow Distance on Quality Settings is too low to be visible.
The problem could be with Realtime Shadows or Baked Shadows, depending on your setup. By default, Unity lights are set up to mixed mode. We will start explaining the settings for Realtime Shadows:
First, we'll take a look a the Light settings. You can find them in the Inspector when you have selected light in the scene. Remember that each light in the scene will have its own configuration, so you must check them all.
- Baking setting: This option specifies what light will affect. There are three options; RealTime, Baked, and Mixed. For real-time shows to appear, make sure either RealTime or Mixed are selected.
- Shadow Type: The options under this tab are: Hard shadows, Soft shadows, and No Shadows. We need to make sure Hard or Soft shadows are selected for Real-Time shadows.
- Culling Mask: These masks allow you to specify which layers the light will affect. For example, if we have a character set to a custom layer called "Character" and want him to be affected by the light, the culling mask needs to include the "Character" layer.
We will also need to make sure the objects in the scene are correctly configured to receive and cast shadows. We go to the Mesh Renderer or Skinned Mesh Component in the inspector of the Object we want to check.
- Static: This toggles whether the object is static in the scene or dynamic. Leave this unticked for real-time lighting.
- Cast shadows and Receive shadows: These specify whether the mesh renderer will cast and receive shadows. Note: Real-Time lit objects will not receive baked shadows. See Mixed mode lighting - Baked objects casting shadows on realtime objects for additional information.
If the light/object settings didn't solve the issue, you could look at the Quality settings window, which can be found by going to the top menu and selecting Edit > Project Settings > Quality. This will open the window above in the inspector. From here, we can check the red highlighted areas:
- Shadows: You can specify the shadows allowed to render in the project in this field. Make sure either Hard Shadows only or Hard and Soft Shadows is selected.
- Shadow Distance: This is the maximum distance from the camera at which shadows will be visible. Objects set to cast Real-Time shadows beyond this distance will not be rendered.
Here, we will cover the important settings for Baked Shadows that could be the cause of most problems.
Let's take a look at the Light settings. You can find them in the Inspector when you have selected light in the scene.
- Mode: Like the Real-Time settings on a light, the mode option field in the light component needs to be set to either Baked or Mixed for baked shadows to appear.
We also need to make sure the objects in the scene are correctly configured to receive and cast shadows. Go to the Mesh Renderer Component in the inspector of the Object we want to check.
- Static: To specify that this mesh needs to be included in the lightmap baking, the static field must be checked.
- Cast shadows and Receive shadows: Cast Shadows needs to be set to On if the object should cast shadows during baking of the lightmaps. Receive Shadows should be selected if the object needs to receive either baked or Real-Time shadows.
We will also need to set up some parameters for baked lights in the Lighting window. To open it, go to Window > Rendering > Lighting.
- Baked Global Illumination (Baked GI): To enable baking of lightmaps, make sure that Baked Global Illumination is enabled from the Lighting window in the Scene tab.
- Contribute Global Illumination (Contribute GI): There is a Contribute Global Illumination toggle in the Lighting window. This is set to true when a GameObject is set to true in the inspector. This property includes this GameObject's Mesh Renderer in global illumination calculations. These calculations take place while precomputing lighting data at bake time. This property only takes effect if you enable a Global Illumination setting such as Baked Global Illumination or Realtime Global Illumination for this Scene. In the case of requiring the object to be baked and use lightmapped shadows, we need to ticket the lightmap static toggle.