# PropertyField

> Use this to make a field for a SerializedProperty in the Editor.

## Definition

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

## PropertyField(Rect, SerializedProperty, bool)

Use this to make a field for a [SerializedProperty](/engine/6000.5/script-reference/unityeditor/serializedproperty.md) in the Editor.

```csharp
public static bool PropertyField(Rect position, SerializedProperty property, bool includeChildren)
```

### Parameters

**** (\[Rect]\(/engine/6000.5/script-reference/unityengine/rect)): Rectangle on the screen to use for the property field.**** (\[SerializedProperty]\(/engine/6000.5/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).

### Returns

| Type                                                          | Description                                                                                              |
| ------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------- |
| [bool](https://learn.microsoft.com/dotnet/api/system.boolean) | True if the property has children and is expanded and includeChildren was set to false; otherwise false. |

### Remarks

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

### Examples

```csharp
//Attach a script like this to the GameObject you would like to have a custom Editor window.

using UnityEngine;

public class MyScript : MonoBehaviour
{
    public int myInt = 90;
}
```

```csharp
//Create a folder and name it “Editor” and place this second script within it. To do this right click within the Assets directory and go to Create>Folder
//Ensure you insert your first script’s name as a parameter in the CustomEditor e.g. [CustomEditor(typeof(MyScript))]

using UnityEngine;
using UnityEditor;

// Custom Editor using SerializedProperties.
// Make sure to put the name of the script on your GameObject in here
[CustomEditor(typeof(MyScript))]
// Automatic handling of multi-object editing, undo, and Prefab overrides.
[CanEditMultipleObjects]

public class EditorGUIPropertyField : Editor
{
    SerializedProperty m_IntProperty;

    void OnEnable()
    {
        // Fetch the objects from the MyScript script to display in the inspector
        m_IntProperty = serializedObject.FindProperty("myInt");
    }

    public override void OnInspectorGUI()
    {
        //The variables and GameObject from the GameObject script are displayed in the Inspector and have the appropriate label
        EditorGUI.PropertyField(new Rect(0, 300, 500, 30), m_IntProperty, new GUIContent("Int : "));

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

## PropertyField(Rect, SerializedProperty, GUIContent, bool)

Use this to make a field for a [SerializedProperty](/engine/6000.5/script-reference/unityeditor/serializedproperty.md) in the Editor.

```csharp
public static bool PropertyField(Rect position, SerializedProperty property, GUIContent label, bool includeChildren)
```

### Parameters

**** (\[Rect]\(/engine/6000.5/script-reference/unityengine/rect)): Rectangle on the screen to use for the property field.**** (\[SerializedProperty]\(/engine/6000.5/script-reference/unityeditor/serializedproperty)): The SerializedProperty to make a field for.**** (\[GUIContent]\(/engine/6000.5/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).

### Returns

| Type                                                          | Description                                                                                              |
| ------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------- |
| [bool](https://learn.microsoft.com/dotnet/api/system.boolean) | True if the property has children and is expanded and includeChildren was set to false; otherwise false. |

### Remarks

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

### Examples

```csharp
//Attach a script like this to the GameObject you would like to have a custom Editor window.

using UnityEngine;

public class MyScript : MonoBehaviour
{
    public int myInt = 90;
}
```

```csharp
//Create a folder and name it “Editor” and place this second script within it. To do this right click within the Assets directory and go to Create>Folder
//Ensure you insert your first script’s name as a parameter in the CustomEditor e.g. [CustomEditor(typeof(MyScript))]

using UnityEngine;
using UnityEditor;

// Custom Editor using SerializedProperties.
// Make sure to put the name of the script on your GameObject in here
[CustomEditor(typeof(MyScript))]
// Automatic handling of multi-object editing, undo, and Prefab overrides.
[CanEditMultipleObjects]

public class EditorGUIPropertyField : Editor
{
    SerializedProperty m_IntProperty;

    void OnEnable()
    {
        // Fetch the objects from the MyScript script to display in the inspector
        m_IntProperty = serializedObject.FindProperty("myInt");
    }

    public override void OnInspectorGUI()
    {
        //The variables and GameObject from the GameObject script are displayed in the Inspector and have the appropriate label
        EditorGUI.PropertyField(new Rect(0, 300, 500, 30), m_IntProperty, new GUIContent("Int : "));

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