Condition
The base class for all user-accessible conditions in a Condition.StateMachine graph.
Read time 2 minutesLast updated 6 days ago
Definition
- Type: Class
- Namespace: Unity.GraphToolkit.Editor
- Assembly: UnityEditor
- Implements: ICondition
public abstract class Condition : ICondition
Remarks
A condition is a single test evaluated on a transition; conditions are combined with the built-in group condition (logical /) to decide whether a transition is taken. Derive from Condition<T> to define a custom condition type with its serialized value, or derive from this class directly to define a valueless condition, such as a trigger, displayed as a label-only row in the transition inspector.
ANDORTo make a custom condition available in a state machine, decorate the derived type with UseWithStateMachineAttribute for the relevant Condition.StateMachine type. Conditions defined in the same assembly as the state machine are available without the attribute, unless the state machine sets StateMachineOptions.DisableAutoInclusionOfStatesFromStateMachineAssembly. Available conditions appear in the menu of a transition's condition list, labeled with the title of a ConditionAttribute applied to the condition type when present, otherwise with the condition type name formatted for display.
AddSee also:
-
Condition<T> for the base class used to define custom conditions
-
ConditionView<T> for adding custom UI to a condition's row in the transition inspector
-
Condition.StateMachine for the graph type that contains transitions and conditions
-
State for the base class used to define custom states
-
IGroupCondition for reading a transition's condition hierarchy
Examples
[Serializable][UseWithStateMachine(typeof(MyStateMachine))][Condition("Health Threshold")]public class Health : Condition<float>{ public override string Tooltip => "Compares the current health against this value."; protected override bool DisplayComparisonDropdown => true;}
Properties
Property | Description |
|---|---|
| Icon | The icon displayed for this condition in the transition inspector, or |
| ID | The globally unique identifier for this condition. |
| Rule | The rule this condition belongs to, or |
| StateMachine | The Condition.StateMachine that contains this condition, or |
| Title | The label displayed for the condition in the transition inspector. |
| Tooltip | The text displayed when hovering over the condition in the transition inspector. |
Static Methods
Method | Description |
|---|---|
| CreateGroupCondition | Creates a new empty group condition. |
| CreateVariableCondition | Creates a new variable condition. |