zaro

How do I change the light layer in Unity?

Published in Unity Graphics 3 mins read

To change the light layer in Unity, you need to modify the Light Layer names within your project's graphics settings, specifically in the Universal Render Pipeline (URP) global settings.

Here's a step-by-step guide:

  1. Open Project Settings: In the Unity Editor, go to Edit > Project Settings.

  2. Navigate to Graphics: In the Project Settings window, select Graphics.

  3. Locate URP Global Settings: You should see a section indicating your current Scriptable Render Pipeline Settings. This is usually your URP Global Settings asset. If there's no setting here or the incorrect one, create a new URP Global Settings asset, and drag this new asset into this slot.

  4. Edit Light Layer Names: Within the URP Global Settings asset, find the Light Layer Names (3D) section.

  5. Modify the Names: This section lists the names of your light layers. You can change these names to whatever is suitable for your project's needs. The default names are usually "Light Layer 0," "Light Layer 1," etc. Changing the names here affects how you refer to them in code and the Unity Editor.

Explanation and Additional Information:

  • What are Light Layers? Light Layers allow you to selectively illuminate objects in your scene. Each object and each light can be assigned to a specific light layer. Only objects in a light layer will be illuminated by lights in the same light layer. This is a powerful technique for optimizing performance and creating complex lighting effects.

  • How to Assign Objects and Lights to Light Layers:

    • Objects: Select the GameObject in your scene. In the Inspector window, look for the Static dropdown at the top. Click it, and you'll find an option labeled Lightmap Static. Expanding that list, you will find Light Layer, which lets you set which light layer the object belongs to.
    • Lights: Select the Light GameObject in your scene. In the Inspector window, you'll find the Rendering section. Here, you'll find a Light Layers property. You can select which light layers this light affects.
  • Practical Use Cases:

    • Performance Optimization: By assigning different groups of lights and objects to different layers, you can reduce the number of lighting calculations the engine needs to perform, leading to improved performance.
    • Selective Lighting Effects: You can create lighting effects that only affect specific parts of your scene, adding more control and realism to your lighting. For example, you might have a spotlight that only illuminates a character, while other lights illuminate the environment.
    • Interior/Exterior Lighting: You could assign interior objects to one light layer and exterior objects to another, then have separate sets of lights for each area.
  • Limitations: URP supports up to 8 light layers.

By configuring Light Layers in the URP Global Settings, you can effectively manage and optimize the lighting in your Unity projects.