Documentation

Unity Engine


User Manual

Script Reference

Unity Engine


Condition

The base class for all user-accessible conditions in a Condition.StateMachine graph.
Read time 2 minutesLast updated 6 days ago

Definition

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
AND
/
OR
) 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.
To 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
Add
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.
See 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

IconThe icon displayed for this condition in the transition inspector, or
null
if none is set.
IDThe globally unique identifier for this condition.
RuleThe rule this condition belongs to, or
null
when the condition is not part of one.
StateMachineThe Condition.StateMachine that contains this condition, or
null
when the condition is not part of a state machine.
TitleThe label displayed for the condition in the transition inspector.
TooltipThe text displayed when hovering over the condition in the transition inspector.

Static Methods

Method

Description

CreateGroupConditionCreates a new empty group condition.
CreateVariableConditionCreates a new variable condition.