Version: Unity 6.6 Alpha (6000.6)
LanguageEnglish
  • C#

LayerMask.ToString

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

Declaration

public string ToString();

Description

Given a layer mask, returns a comma seperated list of the names of the layers in this mask. The names are as defined in either a Builtin or a User Layer in the Tags and Layers manager.

using UnityEngine;

public class Example : MonoBehaviour { void Start() { // Converts an int to a layer mask and prints all the layer names. // As the value is 3, it will print "Default" and "TransparentFX". // 2^0 + 2^1 = 1 + 2 = 3

int number = 3; LayerMask layerMask;

// ✅ This line is the key to this example: // Implicitly converts the integer 'number' into a LayerMask. // This uses LayerMask.LayerMask implicitly. layerMask = number;

// "Default, TransparentFX" Debug.Log(layerMask.ToString()); } }

Returns either the Layer name, or the bit index if no name is set. If called off of the Main Thread, the enabled Layer indices in the mask are returned instead of each layer name as layer name retrieval must occur on the Main Thread.