# LayerField

> Make a layer selection field.

## Definition

* **Type:** Method
* **Namespace:** [UnityEditor](/engine/6000.3/script-reference/unityeditor.md)
* **Assembly:** UnityEditor

## LayerField(int, GUILayoutOption\[])

Make a layer selection field.

```csharp
public static int LayerField(int layer, params GUILayoutOption[] options)
```

### Parameters

**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): The layer shown in the field.**** (\[GUILayoutOption\[]]\(/engine/6000.3/script-reference/unityengine/guilayoutoption)): An optional list of layout options that specify extra layout properties. Any values passed in here will override settings defined by the `style`.\
&#x20;Additional Resources: [GUILayout.Width](/engine/6000.3/script-reference/unityengine/guilayout/width.md), [GUILayout.Height](/engine/6000.3/script-reference/unityengine/guilayout/height.md), [GUILayout.MinWidth](/engine/6000.3/script-reference/unityengine/guilayout/minwidth.md), [GUILayout.MaxWidth](/engine/6000.3/script-reference/unityengine/guilayout/maxwidth.md), [GUILayout.MinHeight](/engine/6000.3/script-reference/unityengine/guilayout/minheight.md), [GUILayout.MaxHeight](/engine/6000.3/script-reference/unityengine/guilayout/maxheight.md), [GUILayout.ExpandWidth](/engine/6000.3/script-reference/unityengine/guilayout/expandwidth.md), [GUILayout.ExpandHeight](/engine/6000.3/script-reference/unityengine/guilayout/expandheight.md).

### Returns

| Type                                                       | Description                     |
| ---------------------------------------------------------- | ------------------------------- |
| [int](https://learn.microsoft.com/dotnet/api/system.int32) | The layer selected by the user. |

### Remarks

![EditorGUILayoutLayerField (LayerField)](/api/media?file=/engine/6000.3/media/images/EditorGUILayoutLayerField.png)

*Set the layer of the selected GameObjects.*

### Examples

```csharp
// Simple editor script that lets you set the layer for the
// selected GameObjects.

using UnityEngine;
using UnityEditor;

public class LayerFieldExample : EditorWindow
{
    static int selectedLayer = 0;

    [MenuItem("Examples/Layer Field usage")]
    static void Init()
    {
        LayerFieldExample window = (LayerFieldExample)GetWindow(typeof(LayerFieldExample));
        window.Show();
    }

    // Disable menu if we dont have at least 1 gameobject selected
    [MenuItem("Examples/Layer Field usage", true)]
    static bool ValidateSelection()
    {
        return Selection.activeGameObject != null;
    }

    void OnGUI()
    {
        selectedLayer = EditorGUILayout.LayerField("Layer for Objects:", selectedLayer);
        if (GUILayout.Button("Set Layer!"))
            SetLayer();
    }

    static void SetLayer()
    {
        foreach (var go in Selection.gameObjects)
            go.layer = selectedLayer;
    }
}
```

## LayerField(int, GUIStyle, GUILayoutOption\[])

Make a layer selection field.

```csharp
public static int LayerField(int layer, GUIStyle style, params GUILayoutOption[] options)
```

### Parameters

**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): The layer shown in the field.**** (\[GUIStyle]\(/engine/6000.3/script-reference/unityengine/guistyle)): Optional [GUIStyle](/engine/6000.3/script-reference/unityengine/guistyle.md).**** (\[GUILayoutOption\[]]\(/engine/6000.3/script-reference/unityengine/guilayoutoption)): An optional list of layout options that specify extra layout properties. Any values passed in here will override settings defined by the `style`.\
&#x20;Additional Resources: [GUILayout.Width](/engine/6000.3/script-reference/unityengine/guilayout/width.md), [GUILayout.Height](/engine/6000.3/script-reference/unityengine/guilayout/height.md), [GUILayout.MinWidth](/engine/6000.3/script-reference/unityengine/guilayout/minwidth.md), [GUILayout.MaxWidth](/engine/6000.3/script-reference/unityengine/guilayout/maxwidth.md), [GUILayout.MinHeight](/engine/6000.3/script-reference/unityengine/guilayout/minheight.md), [GUILayout.MaxHeight](/engine/6000.3/script-reference/unityengine/guilayout/maxheight.md), [GUILayout.ExpandWidth](/engine/6000.3/script-reference/unityengine/guilayout/expandwidth.md), [GUILayout.ExpandHeight](/engine/6000.3/script-reference/unityengine/guilayout/expandheight.md).

### Returns

| Type                                                       | Description                     |
| ---------------------------------------------------------- | ------------------------------- |
| [int](https://learn.microsoft.com/dotnet/api/system.int32) | The layer selected by the user. |

### Remarks

![EditorGUILayoutLayerField (LayerField)](/api/media?file=/engine/6000.3/media/images/EditorGUILayoutLayerField.png)

*Set the layer of the selected GameObjects.*

### Examples

```csharp
// Simple editor script that lets you set the layer for the
// selected GameObjects.

using UnityEngine;
using UnityEditor;

public class LayerFieldExample : EditorWindow
{
    static int selectedLayer = 0;

    [MenuItem("Examples/Layer Field usage")]
    static void Init()
    {
        LayerFieldExample window = (LayerFieldExample)GetWindow(typeof(LayerFieldExample));
        window.Show();
    }

    // Disable menu if we dont have at least 1 gameobject selected
    [MenuItem("Examples/Layer Field usage", true)]
    static bool ValidateSelection()
    {
        return Selection.activeGameObject != null;
    }

    void OnGUI()
    {
        selectedLayer = EditorGUILayout.LayerField("Layer for Objects:", selectedLayer);
        if (GUILayout.Button("Set Layer!"))
            SetLayer();
    }

    static void SetLayer()
    {
        foreach (var go in Selection.gameObjects)
            go.layer = selectedLayer;
    }
}
```

## LayerField(string, int, GUILayoutOption\[])

Make a layer selection field.

```csharp
public static int LayerField(string label, int layer, params GUILayoutOption[] options)
```

### Parameters

**** (\[string]\(https\://learn.microsoft.com/dotnet/api/system.string)): Optional label in front of the field.**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): The layer shown in the field.**** (\[GUILayoutOption\[]]\(/engine/6000.3/script-reference/unityengine/guilayoutoption)): An optional list of layout options that specify extra layout properties. Any values passed in here will override settings defined by the `style`.\
&#x20;Additional Resources: [GUILayout.Width](/engine/6000.3/script-reference/unityengine/guilayout/width.md), [GUILayout.Height](/engine/6000.3/script-reference/unityengine/guilayout/height.md), [GUILayout.MinWidth](/engine/6000.3/script-reference/unityengine/guilayout/minwidth.md), [GUILayout.MaxWidth](/engine/6000.3/script-reference/unityengine/guilayout/maxwidth.md), [GUILayout.MinHeight](/engine/6000.3/script-reference/unityengine/guilayout/minheight.md), [GUILayout.MaxHeight](/engine/6000.3/script-reference/unityengine/guilayout/maxheight.md), [GUILayout.ExpandWidth](/engine/6000.3/script-reference/unityengine/guilayout/expandwidth.md), [GUILayout.ExpandHeight](/engine/6000.3/script-reference/unityengine/guilayout/expandheight.md).

### Returns

| Type                                                       | Description                     |
| ---------------------------------------------------------- | ------------------------------- |
| [int](https://learn.microsoft.com/dotnet/api/system.int32) | The layer selected by the user. |

### Remarks

![EditorGUILayoutLayerField (LayerField)](/api/media?file=/engine/6000.3/media/images/EditorGUILayoutLayerField.png)

*Set the layer of the selected GameObjects.*

### Examples

```csharp
// Simple editor script that lets you set the layer for the
// selected GameObjects.

using UnityEngine;
using UnityEditor;

public class LayerFieldExample : EditorWindow
{
    static int selectedLayer = 0;

    [MenuItem("Examples/Layer Field usage")]
    static void Init()
    {
        LayerFieldExample window = (LayerFieldExample)GetWindow(typeof(LayerFieldExample));
        window.Show();
    }

    // Disable menu if we dont have at least 1 gameobject selected
    [MenuItem("Examples/Layer Field usage", true)]
    static bool ValidateSelection()
    {
        return Selection.activeGameObject != null;
    }

    void OnGUI()
    {
        selectedLayer = EditorGUILayout.LayerField("Layer for Objects:", selectedLayer);
        if (GUILayout.Button("Set Layer!"))
            SetLayer();
    }

    static void SetLayer()
    {
        foreach (var go in Selection.gameObjects)
            go.layer = selectedLayer;
    }
}
```

## LayerField(string, int, GUIStyle, GUILayoutOption\[])

Make a layer selection field.

```csharp
public static int LayerField(string label, int layer, GUIStyle style, params GUILayoutOption[] options)
```

### Parameters

**** (\[string]\(https\://learn.microsoft.com/dotnet/api/system.string)): Optional label in front of the field.**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): The layer shown in the field.**** (\[GUIStyle]\(/engine/6000.3/script-reference/unityengine/guistyle)): Optional [GUIStyle](/engine/6000.3/script-reference/unityengine/guistyle.md).**** (\[GUILayoutOption\[]]\(/engine/6000.3/script-reference/unityengine/guilayoutoption)): An optional list of layout options that specify extra layout properties. Any values passed in here will override settings defined by the `style`.\
&#x20;Additional Resources: [GUILayout.Width](/engine/6000.3/script-reference/unityengine/guilayout/width.md), [GUILayout.Height](/engine/6000.3/script-reference/unityengine/guilayout/height.md), [GUILayout.MinWidth](/engine/6000.3/script-reference/unityengine/guilayout/minwidth.md), [GUILayout.MaxWidth](/engine/6000.3/script-reference/unityengine/guilayout/maxwidth.md), [GUILayout.MinHeight](/engine/6000.3/script-reference/unityengine/guilayout/minheight.md), [GUILayout.MaxHeight](/engine/6000.3/script-reference/unityengine/guilayout/maxheight.md), [GUILayout.ExpandWidth](/engine/6000.3/script-reference/unityengine/guilayout/expandwidth.md), [GUILayout.ExpandHeight](/engine/6000.3/script-reference/unityengine/guilayout/expandheight.md).

### Returns

| Type                                                       | Description                     |
| ---------------------------------------------------------- | ------------------------------- |
| [int](https://learn.microsoft.com/dotnet/api/system.int32) | The layer selected by the user. |

### Remarks

![EditorGUILayoutLayerField (LayerField)](/api/media?file=/engine/6000.3/media/images/EditorGUILayoutLayerField.png)

*Set the layer of the selected GameObjects.*

### Examples

```csharp
// Simple editor script that lets you set the layer for the
// selected GameObjects.

using UnityEngine;
using UnityEditor;

public class LayerFieldExample : EditorWindow
{
    static int selectedLayer = 0;

    [MenuItem("Examples/Layer Field usage")]
    static void Init()
    {
        LayerFieldExample window = (LayerFieldExample)GetWindow(typeof(LayerFieldExample));
        window.Show();
    }

    // Disable menu if we dont have at least 1 gameobject selected
    [MenuItem("Examples/Layer Field usage", true)]
    static bool ValidateSelection()
    {
        return Selection.activeGameObject != null;
    }

    void OnGUI()
    {
        selectedLayer = EditorGUILayout.LayerField("Layer for Objects:", selectedLayer);
        if (GUILayout.Button("Set Layer!"))
            SetLayer();
    }

    static void SetLayer()
    {
        foreach (var go in Selection.gameObjects)
            go.layer = selectedLayer;
    }
}
```

## LayerField(GUIContent, int, GUILayoutOption\[])

Make a layer selection field.

```csharp
public static int LayerField(GUIContent label, int layer, params GUILayoutOption[] options)
```

### Parameters

**** (\[GUIContent]\(/engine/6000.3/script-reference/unityengine/guicontent)): Optional label in front of the field.**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): The layer shown in the field.**** (\[GUILayoutOption\[]]\(/engine/6000.3/script-reference/unityengine/guilayoutoption)): An optional list of layout options that specify extra layout properties. Any values passed in here will override settings defined by the `style`.\
&#x20;Additional Resources: [GUILayout.Width](/engine/6000.3/script-reference/unityengine/guilayout/width.md), [GUILayout.Height](/engine/6000.3/script-reference/unityengine/guilayout/height.md), [GUILayout.MinWidth](/engine/6000.3/script-reference/unityengine/guilayout/minwidth.md), [GUILayout.MaxWidth](/engine/6000.3/script-reference/unityengine/guilayout/maxwidth.md), [GUILayout.MinHeight](/engine/6000.3/script-reference/unityengine/guilayout/minheight.md), [GUILayout.MaxHeight](/engine/6000.3/script-reference/unityengine/guilayout/maxheight.md), [GUILayout.ExpandWidth](/engine/6000.3/script-reference/unityengine/guilayout/expandwidth.md), [GUILayout.ExpandHeight](/engine/6000.3/script-reference/unityengine/guilayout/expandheight.md).

### Returns

| Type                                                       | Description                     |
| ---------------------------------------------------------- | ------------------------------- |
| [int](https://learn.microsoft.com/dotnet/api/system.int32) | The layer selected by the user. |

### Remarks

![EditorGUILayoutLayerField (LayerField)](/api/media?file=/engine/6000.3/media/images/EditorGUILayoutLayerField.png)

*Set the layer of the selected GameObjects.*

### Examples

```csharp
// Simple editor script that lets you set the layer for the
// selected GameObjects.

using UnityEngine;
using UnityEditor;

public class LayerFieldExample : EditorWindow
{
    static int selectedLayer = 0;

    [MenuItem("Examples/Layer Field usage")]
    static void Init()
    {
        LayerFieldExample window = (LayerFieldExample)GetWindow(typeof(LayerFieldExample));
        window.Show();
    }

    // Disable menu if we dont have at least 1 gameobject selected
    [MenuItem("Examples/Layer Field usage", true)]
    static bool ValidateSelection()
    {
        return Selection.activeGameObject != null;
    }

    void OnGUI()
    {
        selectedLayer = EditorGUILayout.LayerField("Layer for Objects:", selectedLayer);
        if (GUILayout.Button("Set Layer!"))
            SetLayer();
    }

    static void SetLayer()
    {
        foreach (var go in Selection.gameObjects)
            go.layer = selectedLayer;
    }
}
```

## LayerField(GUIContent, int, GUIStyle, GUILayoutOption\[])

Make a layer selection field.

```csharp
public static int LayerField(GUIContent label, int layer, GUIStyle style, params GUILayoutOption[] options)
```

### Parameters

**** (\[GUIContent]\(/engine/6000.3/script-reference/unityengine/guicontent)): Optional label in front of the field.**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): The layer shown in the field.**** (\[GUIStyle]\(/engine/6000.3/script-reference/unityengine/guistyle)): Optional [GUIStyle](/engine/6000.3/script-reference/unityengine/guistyle.md).**** (\[GUILayoutOption\[]]\(/engine/6000.3/script-reference/unityengine/guilayoutoption)): An optional list of layout options that specify extra layout properties. Any values passed in here will override settings defined by the `style`.\
&#x20;Additional Resources: [GUILayout.Width](/engine/6000.3/script-reference/unityengine/guilayout/width.md), [GUILayout.Height](/engine/6000.3/script-reference/unityengine/guilayout/height.md), [GUILayout.MinWidth](/engine/6000.3/script-reference/unityengine/guilayout/minwidth.md), [GUILayout.MaxWidth](/engine/6000.3/script-reference/unityengine/guilayout/maxwidth.md), [GUILayout.MinHeight](/engine/6000.3/script-reference/unityengine/guilayout/minheight.md), [GUILayout.MaxHeight](/engine/6000.3/script-reference/unityengine/guilayout/maxheight.md), [GUILayout.ExpandWidth](/engine/6000.3/script-reference/unityengine/guilayout/expandwidth.md), [GUILayout.ExpandHeight](/engine/6000.3/script-reference/unityengine/guilayout/expandheight.md).

### Returns

| Type                                                       | Description                     |
| ---------------------------------------------------------- | ------------------------------- |
| [int](https://learn.microsoft.com/dotnet/api/system.int32) | The layer selected by the user. |

### Remarks

![EditorGUILayoutLayerField (LayerField)](/api/media?file=/engine/6000.3/media/images/EditorGUILayoutLayerField.png)

*Set the layer of the selected GameObjects.*

### Examples

```csharp
// Simple editor script that lets you set the layer for the
// selected GameObjects.

using UnityEngine;
using UnityEditor;

public class LayerFieldExample : EditorWindow
{
    static int selectedLayer = 0;

    [MenuItem("Examples/Layer Field usage")]
    static void Init()
    {
        LayerFieldExample window = (LayerFieldExample)GetWindow(typeof(LayerFieldExample));
        window.Show();
    }

    // Disable menu if we dont have at least 1 gameobject selected
    [MenuItem("Examples/Layer Field usage", true)]
    static bool ValidateSelection()
    {
        return Selection.activeGameObject != null;
    }

    void OnGUI()
    {
        selectedLayer = EditorGUILayout.LayerField("Layer for Objects:", selectedLayer);
        if (GUILayout.Button("Set Layer!"))
            SetLayer();
    }

    static void SetLayer()
    {
        foreach (var go in Selection.gameObjects)
            go.layer = selectedLayer;
    }
}
```
