# ConditionView<T>

> Derive from this class to add custom UI to the view generated for a specific ConditionView<T>.Condition type in the transition inspector.

## Definition

* **Type:** Class
* **Namespace:** [Unity.GraphToolkit.Editor](/engine/6000.7/script-reference/unity/graphtoolkit/editor.md)
* **Assembly:** UnityEditor

```csharp
public class ConditionView<T> where T : Condition
```

## Remarks

A [VisualElement](/engine/6000.7/script-reference/unityengine/uielements/visualelement.md) row is built for every [ConditionView\<T>.Condition](/engine/6000.7/script-reference/unity/graphtoolkit/editor/conditionview1/condition.md) that appears in a transition's condition list. A [ConditionView\<T>](/engine/6000.7/script-reference/unity/graphtoolkit/editor/conditionview1.md) lets you inject custom UI into that row. Subclasses are discovered by their type parameter: for a [ConditionView\<T>.Condition](/engine/6000.7/script-reference/unity/graphtoolkit/editor/conditionview1/condition.md) of type `T`, the concrete [ConditionView\<T>](/engine/6000.7/script-reference/unity/graphtoolkit/editor/conditionview1.md) whose type argument matches is used, walking up the [ConditionView\<T>.Condition](/engine/6000.7/script-reference/unity/graphtoolkit/editor/conditionview1/condition.md) inheritance chain if there is no exact match.

The [ConditionView\<T>.Condition](/engine/6000.7/script-reference/unity/graphtoolkit/editor/conditionview1/condition.md) instance is available through [ConditionView\<T>.Condition](/engine/6000.7/script-reference/unity/graphtoolkit/editor/conditionview1/condition.md) once the view is constructed. To add custom UI next to the built-in condition UI, override [ConditionView\<T>.OnViewBuilt](/engine/6000.7/script-reference/unity/graphtoolkit/editor/conditionview1/onviewbuilt.md) and add your custom UI to [IConditionView.Root](/engine/6000.7/script-reference/unity/graphtoolkit/editor/iconditionview/root.md). Do not remove or reparent the built-in elements. Use instead the relevant display toggle. [ConditionView\<T>.DisplayValueField](/engine/6000.7/script-reference/unity/graphtoolkit/editor/conditionview1/displayvaluefield.md)[ConditionView\<T>.DisplayTitleLabel](/engine/6000.7/script-reference/unity/graphtoolkit/editor/conditionview1/displaytitlelabel.md)[Condition\<T>.DisplayComparisonDropdown](/engine/6000.7/script-reference/unity/graphtoolkit/editor/condition1/displaycomparisondropdown.md)**Important:** allocate custom UI in [ConditionView\<T>.OnViewBuilt](/engine/6000.7/script-reference/unity/graphtoolkit/editor/conditionview1/onviewbuilt.md). Do not allocate UI in [ConditionView\<T>.OnViewAttached](/engine/6000.7/script-reference/unity/graphtoolkit/editor/conditionview1/onviewattached.md): that callback can fire multiple times during the view's lifetime, and any UI you allocate there accumulates as duplicates. Instances of this class are created with the row and are never serialized; do not store state in them that must outlive the view.

Exceptions thrown by the view's constructor or callbacks are logged and do not break the inspector: the condition row still renders its built-in UI.

## Examples

```csharp
// The Condition type that this view customizes.
[Serializable]
public class Health : Condition<float>
{
    protected override string Title => "Health";
}

// This view is constructed for every Health condition row in the transition inspector.
class HealthConditionView : ConditionView<Health>
{
    // Replace the built-in value field with the controls built in OnViewBuilt.
    protected override bool DisplayValueField => false;

    public override void OnViewBuilt()
    {
        // Allocate custom UI once, after the built-in UI is ready.
        var slider = new Slider(0f, 100f) { value = Condition.Value };
        slider.RegisterValueChangedCallback(evt =>
        {
            // Record the write so it is undoable and marks the asset dirty.
            var stateMachine = Condition.StateMachine;
            stateMachine.UndoBeginRecordStateMachine("Change health threshold", Condition);
            Condition.Value = evt.newValue;
            stateMachine.UndoEndRecordStateMachine();
        });

        // Style custom UI with USS: load a stylesheet onto the row's content container...
        View.Root.styleSheets.Add(AssetDatabase.LoadAssetAtPath<StyleSheet>("Assets/HealthCondition.uss"));
        // ...and tag elements with classes for it to match.
        slider.AddToClassList("health-condition__slider");

        View.Root.Add(slider);
    }
}
```

## Properties

| Property                                                                                                           | Description                                                                                                                                                      |
| ------------------------------------------------------------------------------------------------------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [Condition](/engine/6000.7/script-reference/unity/graphtoolkit/editor/conditionview1/condition.md)                 | The [ConditionView\<T>.Condition](/engine/6000.7/script-reference/unity/graphtoolkit/editor/conditionview1/condition.md) instance this view customizes.          |
| [DisplayTitleLabel](/engine/6000.7/script-reference/unity/graphtoolkit/editor/conditionview1/displaytitlelabel.md) | Whether the built-in title label is displayed.                                                                                                                   |
| [DisplayValueField](/engine/6000.7/script-reference/unity/graphtoolkit/editor/conditionview1/displayvaluefield.md) | Whether the built-in field for the condition's value is displayed.                                                                                               |
| [View](/engine/6000.7/script-reference/unity/graphtoolkit/editor/conditionview1/view.md)                           | The generated view for this condition. Add custom UI to [IConditionView.Root](/engine/6000.7/script-reference/unity/graphtoolkit/editor/iconditionview/root.md). |

## Methods

| Method                                                                                                               | Description                                                                                |
| -------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------ |
| [OnConditionChanged](/engine/6000.7/script-reference/unity/graphtoolkit/editor/conditionview1/onconditionchanged.md) | Called after the condition's data changes and the built-in UI has refreshed to reflect it. |
| [OnViewAttached](/engine/6000.7/script-reference/unity/graphtoolkit/editor/conditionview1/onviewattached.md)         | Called when the condition's row is attached to a UI panel.                                 |
| [OnViewBuilt](/engine/6000.7/script-reference/unity/graphtoolkit/editor/conditionview1/onviewbuilt.md)               | Called once, after the condition's built-in UI is fully constructed.                       |
| [OnViewDetached](/engine/6000.7/script-reference/unity/graphtoolkit/editor/conditionview1/onviewdetached.md)         | Called when the condition's row is detached from its UI panel.                             |
