# PropertyField

> Make a field for SerializedProperty.

## Definition

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

## PropertyField(SerializedProperty, GUILayoutOption\[])

Make a field for [SerializedProperty](/engine/6000.0/script-reference/unityeditor/serializedproperty.md).

```csharp
public static bool PropertyField(SerializedProperty property, params GUILayoutOption[] options)
```

### Parameters

**** (\[SerializedProperty]\(/engine/6000.0/script-reference/unityeditor/serializedproperty)): The SerializedProperty to make a field for.**** (\[GUILayoutOption\[]]\(/engine/6000.0/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.0/script-reference/unityengine/guilayout/width.md), [GUILayout.Height](/engine/6000.0/script-reference/unityengine/guilayout/height.md), [GUILayout.MinWidth](/engine/6000.0/script-reference/unityengine/guilayout/minwidth.md), [GUILayout.MaxWidth](/engine/6000.0/script-reference/unityengine/guilayout/maxwidth.md), [GUILayout.MinHeight](/engine/6000.0/script-reference/unityengine/guilayout/minheight.md), [GUILayout.MaxHeight](/engine/6000.0/script-reference/unityengine/guilayout/maxheight.md), [GUILayout.ExpandWidth](/engine/6000.0/script-reference/unityengine/guilayout/expandwidth.md), [GUILayout.ExpandHeight](/engine/6000.0/script-reference/unityengine/guilayout/expandheight.md).

### Returns

| Type                                                          | Description                                                                                                                                                                                                                      |
| ------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [bool](https://learn.microsoft.com/dotnet/api/system.boolean) | True if the property has children, is expanded, and `includeChildren` is set to false; otherwise false. You can use it to determine the `isExpanded` state of the property and customize the rendering of children if necessary. |

### Remarks

Use this when you want to customise the look of the options for a GameObject in the Inspector. Use this to create fields for Serialized Properties. More information on changing the Editor is available in the [Editor](/engine/6000.0/script-reference/unityeditor/editor.md) section.

Additional Resources: [SerializedProperty](/engine/6000.0/script-reference/unityeditor/serializedproperty.md), [SerializedObject](/engine/6000.0/script-reference/unityeditor/serializedobject.md).

### Examples

```csharp
//The scripts below show how to use a propertyField to change your editor.
//Attach this first script to the GameObject that you would like to control. Add code in this script for any of the actions you require.

using UnityEngine;

public class MyGameObjectScript : MonoBehaviour
{
    public int m_MyInt = 75;
    public Vector3 m_MyVector = new Vector3(20, 1, 0);
    public GameObject m_MyGameObject;
}
```

```csharp
//This next script shows how to call upon variables from the "MyGameObject" Script (the first script) to make custom fields in the Inspector for these variables.

using UnityEngine;
using UnityEditor;

// Custom Editor using SerializedProperties.
// Automatic handling of multi-object editing, undo, and Prefab overrides.
[CustomEditor(typeof(MyGameObjectScript))]
[CanEditMultipleObjects]
public class EditorGUILayoutPropertyField : Editor
{
    SerializedProperty m_IntProp;
    SerializedProperty m_VectorProp;
    SerializedProperty m_GameObjectProp;

    void OnEnable()
    {
        // Fetch the objects from the GameObject script to display in the inspector
        m_IntProp = serializedObject.FindProperty("m_MyInt");
        m_VectorProp = serializedObject.FindProperty("m_MyVector");
        m_GameObjectProp = serializedObject.FindProperty("m_MyGameObject");
    }

    public override void OnInspectorGUI()
    {
        //The variables and GameObject from the MyGameObject script are displayed in the Inspector with appropriate labels
        EditorGUILayout.PropertyField(m_IntProp, new GUIContent("Int Field"), GUILayout.Height(20));
        EditorGUILayout.PropertyField(m_VectorProp, new GUIContent("Vector Object"));
        EditorGUILayout.PropertyField(m_GameObjectProp, new GUIContent("Game Object"));

        // Apply changes to the serializedProperty - always do this at the end of OnInspectorGUI.
        serializedObject.ApplyModifiedProperties();
    }
}
```

## PropertyField(SerializedProperty, GUIContent, GUILayoutOption\[])

Make a field for [SerializedProperty](/engine/6000.0/script-reference/unityeditor/serializedproperty.md).

```csharp
public static bool PropertyField(SerializedProperty property, GUIContent label, params GUILayoutOption[] options)
```

### Parameters

**** (\[SerializedProperty]\(/engine/6000.0/script-reference/unityeditor/serializedproperty)): The SerializedProperty to make a field for.**** (\[GUIContent]\(/engine/6000.0/script-reference/unityengine/guicontent)): Optional label to use. If not specified the label of the property itself is used. Use GUIContent.none to not display a label at all.**** (\[GUILayoutOption\[]]\(/engine/6000.0/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.0/script-reference/unityengine/guilayout/width.md), [GUILayout.Height](/engine/6000.0/script-reference/unityengine/guilayout/height.md), [GUILayout.MinWidth](/engine/6000.0/script-reference/unityengine/guilayout/minwidth.md), [GUILayout.MaxWidth](/engine/6000.0/script-reference/unityengine/guilayout/maxwidth.md), [GUILayout.MinHeight](/engine/6000.0/script-reference/unityengine/guilayout/minheight.md), [GUILayout.MaxHeight](/engine/6000.0/script-reference/unityengine/guilayout/maxheight.md), [GUILayout.ExpandWidth](/engine/6000.0/script-reference/unityengine/guilayout/expandwidth.md), [GUILayout.ExpandHeight](/engine/6000.0/script-reference/unityengine/guilayout/expandheight.md).

### Returns

| Type                                                          | Description                                                                                                                                                                                                                      |
| ------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [bool](https://learn.microsoft.com/dotnet/api/system.boolean) | True if the property has children, is expanded, and `includeChildren` is set to false; otherwise false. You can use it to determine the `isExpanded` state of the property and customize the rendering of children if necessary. |

### Remarks

Use this when you want to customise the look of the options for a GameObject in the Inspector. Use this to create fields for Serialized Properties. More information on changing the Editor is available in the [Editor](/engine/6000.0/script-reference/unityeditor/editor.md) section.

Additional Resources: [SerializedProperty](/engine/6000.0/script-reference/unityeditor/serializedproperty.md), [SerializedObject](/engine/6000.0/script-reference/unityeditor/serializedobject.md).

### Examples

```csharp
//The scripts below show how to use a propertyField to change your editor.
//Attach this first script to the GameObject that you would like to control. Add code in this script for any of the actions you require.

using UnityEngine;

public class MyGameObjectScript : MonoBehaviour
{
    public int m_MyInt = 75;
    public Vector3 m_MyVector = new Vector3(20, 1, 0);
    public GameObject m_MyGameObject;
}
```

```csharp
//This next script shows how to call upon variables from the "MyGameObject" Script (the first script) to make custom fields in the Inspector for these variables.

using UnityEngine;
using UnityEditor;

// Custom Editor using SerializedProperties.
// Automatic handling of multi-object editing, undo, and Prefab overrides.
[CustomEditor(typeof(MyGameObjectScript))]
[CanEditMultipleObjects]
public class EditorGUILayoutPropertyField : Editor
{
    SerializedProperty m_IntProp;
    SerializedProperty m_VectorProp;
    SerializedProperty m_GameObjectProp;

    void OnEnable()
    {
        // Fetch the objects from the GameObject script to display in the inspector
        m_IntProp = serializedObject.FindProperty("m_MyInt");
        m_VectorProp = serializedObject.FindProperty("m_MyVector");
        m_GameObjectProp = serializedObject.FindProperty("m_MyGameObject");
    }

    public override void OnInspectorGUI()
    {
        //The variables and GameObject from the MyGameObject script are displayed in the Inspector with appropriate labels
        EditorGUILayout.PropertyField(m_IntProp, new GUIContent("Int Field"), GUILayout.Height(20));
        EditorGUILayout.PropertyField(m_VectorProp, new GUIContent("Vector Object"));
        EditorGUILayout.PropertyField(m_GameObjectProp, new GUIContent("Game Object"));

        // Apply changes to the serializedProperty - always do this at the end of OnInspectorGUI.
        serializedObject.ApplyModifiedProperties();
    }
}
```

## PropertyField(SerializedProperty, bool, GUILayoutOption\[])

Make a field for [SerializedProperty](/engine/6000.0/script-reference/unityeditor/serializedproperty.md).

```csharp
public static bool PropertyField(SerializedProperty property, bool includeChildren, params GUILayoutOption[] options)
```

### Parameters

**** (\[SerializedProperty]\(/engine/6000.0/script-reference/unityeditor/serializedproperty)): The SerializedProperty to make a field for.**** (\[bool]\(https\://learn.microsoft.com/dotnet/api/system.boolean)): If true the property including children is drawn; otherwise only the control itself (such as only a foldout but nothing below it).**** (\[GUILayoutOption\[]]\(/engine/6000.0/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.0/script-reference/unityengine/guilayout/width.md), [GUILayout.Height](/engine/6000.0/script-reference/unityengine/guilayout/height.md), [GUILayout.MinWidth](/engine/6000.0/script-reference/unityengine/guilayout/minwidth.md), [GUILayout.MaxWidth](/engine/6000.0/script-reference/unityengine/guilayout/maxwidth.md), [GUILayout.MinHeight](/engine/6000.0/script-reference/unityengine/guilayout/minheight.md), [GUILayout.MaxHeight](/engine/6000.0/script-reference/unityengine/guilayout/maxheight.md), [GUILayout.ExpandWidth](/engine/6000.0/script-reference/unityengine/guilayout/expandwidth.md), [GUILayout.ExpandHeight](/engine/6000.0/script-reference/unityengine/guilayout/expandheight.md).

### Returns

| Type                                                          | Description                                                                                                                                                                                                                      |
| ------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [bool](https://learn.microsoft.com/dotnet/api/system.boolean) | True if the property has children, is expanded, and `includeChildren` is set to false; otherwise false. You can use it to determine the `isExpanded` state of the property and customize the rendering of children if necessary. |

### Remarks

Use this when you want to customise the look of the options for a GameObject in the Inspector. Use this to create fields for Serialized Properties. More information on changing the Editor is available in the [Editor](/engine/6000.0/script-reference/unityeditor/editor.md) section.

Additional Resources: [SerializedProperty](/engine/6000.0/script-reference/unityeditor/serializedproperty.md), [SerializedObject](/engine/6000.0/script-reference/unityeditor/serializedobject.md).

### Examples

```csharp
//The scripts below show how to use a propertyField to change your editor.
//Attach this first script to the GameObject that you would like to control. Add code in this script for any of the actions you require.

using UnityEngine;

public class MyGameObjectScript : MonoBehaviour
{
    public int m_MyInt = 75;
    public Vector3 m_MyVector = new Vector3(20, 1, 0);
    public GameObject m_MyGameObject;
}
```

```csharp
//This next script shows how to call upon variables from the "MyGameObject" Script (the first script) to make custom fields in the Inspector for these variables.

using UnityEngine;
using UnityEditor;

// Custom Editor using SerializedProperties.
// Automatic handling of multi-object editing, undo, and Prefab overrides.
[CustomEditor(typeof(MyGameObjectScript))]
[CanEditMultipleObjects]
public class EditorGUILayoutPropertyField : Editor
{
    SerializedProperty m_IntProp;
    SerializedProperty m_VectorProp;
    SerializedProperty m_GameObjectProp;

    void OnEnable()
    {
        // Fetch the objects from the GameObject script to display in the inspector
        m_IntProp = serializedObject.FindProperty("m_MyInt");
        m_VectorProp = serializedObject.FindProperty("m_MyVector");
        m_GameObjectProp = serializedObject.FindProperty("m_MyGameObject");
    }

    public override void OnInspectorGUI()
    {
        //The variables and GameObject from the MyGameObject script are displayed in the Inspector with appropriate labels
        EditorGUILayout.PropertyField(m_IntProp, new GUIContent("Int Field"), GUILayout.Height(20));
        EditorGUILayout.PropertyField(m_VectorProp, new GUIContent("Vector Object"));
        EditorGUILayout.PropertyField(m_GameObjectProp, new GUIContent("Game Object"));

        // Apply changes to the serializedProperty - always do this at the end of OnInspectorGUI.
        serializedObject.ApplyModifiedProperties();
    }
}
```

## PropertyField(SerializedProperty, GUIContent, bool, GUILayoutOption\[])

Make a field for [SerializedProperty](/engine/6000.0/script-reference/unityeditor/serializedproperty.md).

```csharp
public static bool PropertyField(SerializedProperty property, GUIContent label, bool includeChildren, params GUILayoutOption[] options)
```

### Parameters

**** (\[SerializedProperty]\(/engine/6000.0/script-reference/unityeditor/serializedproperty)): The SerializedProperty to make a field for.**** (\[GUIContent]\(/engine/6000.0/script-reference/unityengine/guicontent)): Optional label to use. If not specified the label of the property itself is used. Use GUIContent.none to not display a label at all.**** (\[bool]\(https\://learn.microsoft.com/dotnet/api/system.boolean)): If true the property including children is drawn; otherwise only the control itself (such as only a foldout but nothing below it).**** (\[GUILayoutOption\[]]\(/engine/6000.0/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.0/script-reference/unityengine/guilayout/width.md), [GUILayout.Height](/engine/6000.0/script-reference/unityengine/guilayout/height.md), [GUILayout.MinWidth](/engine/6000.0/script-reference/unityengine/guilayout/minwidth.md), [GUILayout.MaxWidth](/engine/6000.0/script-reference/unityengine/guilayout/maxwidth.md), [GUILayout.MinHeight](/engine/6000.0/script-reference/unityengine/guilayout/minheight.md), [GUILayout.MaxHeight](/engine/6000.0/script-reference/unityengine/guilayout/maxheight.md), [GUILayout.ExpandWidth](/engine/6000.0/script-reference/unityengine/guilayout/expandwidth.md), [GUILayout.ExpandHeight](/engine/6000.0/script-reference/unityengine/guilayout/expandheight.md).

### Returns

| Type                                                          | Description                                                                                                                                                                                                                      |
| ------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [bool](https://learn.microsoft.com/dotnet/api/system.boolean) | True if the property has children, is expanded, and `includeChildren` is set to false; otherwise false. You can use it to determine the `isExpanded` state of the property and customize the rendering of children if necessary. |

### Remarks

Use this when you want to customise the look of the options for a GameObject in the Inspector. Use this to create fields for Serialized Properties. More information on changing the Editor is available in the [Editor](/engine/6000.0/script-reference/unityeditor/editor.md) section.

Additional Resources: [SerializedProperty](/engine/6000.0/script-reference/unityeditor/serializedproperty.md), [SerializedObject](/engine/6000.0/script-reference/unityeditor/serializedobject.md).

### Examples

```csharp
//The scripts below show how to use a propertyField to change your editor.
//Attach this first script to the GameObject that you would like to control. Add code in this script for any of the actions you require.

using UnityEngine;

public class MyGameObjectScript : MonoBehaviour
{
    public int m_MyInt = 75;
    public Vector3 m_MyVector = new Vector3(20, 1, 0);
    public GameObject m_MyGameObject;
}
```

```csharp
//This next script shows how to call upon variables from the "MyGameObject" Script (the first script) to make custom fields in the Inspector for these variables.

using UnityEngine;
using UnityEditor;

// Custom Editor using SerializedProperties.
// Automatic handling of multi-object editing, undo, and Prefab overrides.
[CustomEditor(typeof(MyGameObjectScript))]
[CanEditMultipleObjects]
public class EditorGUILayoutPropertyField : Editor
{
    SerializedProperty m_IntProp;
    SerializedProperty m_VectorProp;
    SerializedProperty m_GameObjectProp;

    void OnEnable()
    {
        // Fetch the objects from the GameObject script to display in the inspector
        m_IntProp = serializedObject.FindProperty("m_MyInt");
        m_VectorProp = serializedObject.FindProperty("m_MyVector");
        m_GameObjectProp = serializedObject.FindProperty("m_MyGameObject");
    }

    public override void OnInspectorGUI()
    {
        //The variables and GameObject from the MyGameObject script are displayed in the Inspector with appropriate labels
        EditorGUILayout.PropertyField(m_IntProp, new GUIContent("Int Field"), GUILayout.Height(20));
        EditorGUILayout.PropertyField(m_VectorProp, new GUIContent("Vector Object"));
        EditorGUILayout.PropertyField(m_GameObjectProp, new GUIContent("Game Object"));

        // Apply changes to the serializedProperty - always do this at the end of OnInspectorGUI.
        serializedObject.ApplyModifiedProperties();
    }
}
```
