Documentation

Unity Engine


User Manual

Script Reference

Unity Engine


GetMask

Given a set of rendering layer names as defined in the Tags and Layers manager, returns the equivalent rendering layer mask for all of them.
Read time 1 minuteLast updated 4 days ago

Definition

  • Type: Method
  • Namespace: UnityEngine
  • Assembly: UnityEngine.CoreModule

GetMask(string[])

Given a set of rendering layer names as defined in the Tags and Layers manager, returns the equivalent rendering layer mask for all of them.
public static uint GetMask(params string[] renderingLayerNames)

Parameters

renderingLayerNames

List of layer names to convert to a rendering layer mask.

Returns

Type

Description

uintThe rendering layer mask created from the renderingLayerNames.

Remarks

using UnityEngine;using UnityEngine.Rendering;public class Example : MonoBehaviour{ void Start() { Debug.Log(RenderingLayerMask.GetMask("UserLayerA", "UserLayerB")); }}
Note: Suppose UserLayerA and UserLayerB are the tenth and eleventh layers. These will have a Rendering Layer values of 10 and 11. To obtain their layer mask value their names can be passed into RenderingLayerMask.GetMask. The argument can either be a list of their names or an array of strings storing their names. In this case the return value will be 2^10 + 2^11 = 3072.

GetMask(ReadOnlySpan<string>)

Given a set of rendering layer names as defined in the Tags and Layers manager, returns the equivalent rendering layer mask for all of them.
public static uint GetMask(ReadOnlySpan<string> renderingLayerNames)

Parameters

renderingLayerNames

Span of layer names to convert to a rendering layer mask.

Returns

Type

Description

uintThe rendering layer mask created from the renderingLayerNames.

Examples

using System;using UnityEngine;using UnityEngine.Rendering;public class Example : MonoBehaviour{ [SerializeField] string[] renderingLayerNames = { "UserLayerA", "UserLayerB" }; void Start() { Debug.Log(RenderingLayerMask.GetMask(new ReadOnlySpan<string>(renderingLayerNames))); }}