Version: 2023.1
Language : English
Uses of layers in Unity
Layer-based collision detection

Create functional layers in Unity

Layers can help to organize the GameObjectsThe fundamental object in Unity scenes, which can represent characters, props, scenery, cameras, waypoints, and more. A GameObject’s functionality is defined by the Components attached to it. More info
See in Glossary
in your sceneA Scene contains the environments and menus of your game. Think of each unique Scene file as a unique level. In each Scene, you place your environments, obstacles, and decorations, essentially designing and building your game in pieces. More info
See in Glossary
. If you create a layer and assign GameObjects to it, you can edit how your GameObjects interact with other GameObjects, dependent on the layer.

Add a new layer

There are two ways you can create a new layer:

  • Select the Tags and Layers window (main menu: Edit > Project Settings > Tags and Layers > Layers).
  • Select a GameObject, select the Layer dropdown in the InspectorA Unity window that displays information about the currently selected GameObject, asset or project settings, allowing you to inspect and edit the values. More info
    See in Glossary
    window, and select Add Layer from the menu.

To remember the intended function for a layer, give it a descriptive name.

Warning: Layer 31 is used internally by the Editor’s Preview window mechanics. To prevent clashes, do not use this layer.

Built-in layers

When you open the layer menu, you can see that some layers are already named. Except for Default and Ignore Raycast, Unity no longer uses these built-in layers for many dedicated purposes; they exist mainly for backward compatibility:

Layer number Layer name Description
1 TransparentFX Unity uses this layer in the flare system.
2 Ignore Raycast Physics ray cast APIs ignore this layer by default.
3 Water Unity’s Standard Assets for Unity 2018.4 use this layer
4 UI(User Interface) Allows a user to interact with your application. Unity currently supports three UI systems. More info
See in Glossary
The Unity UI uses this as the default layer for UI elements.

You can still use these layers, but you can’t rename or delete them.

Add GameObjects to a layer

To assign a GameObject to a layer, select the GameObject, go to the Inspector window and select the dropdown next to Layer. This menu shows the layers that have names so you can select which one works best for your GameObject.

You can only assign each GameObject to one layer, but you can add multiple GameObjects to one layer.

Additional resources

Uses of layers in Unity
Layer-based collision detection
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961