Skip to main content

Build and Test a Visual Condition Tree

TinyGiants
Unity Games & Tools Developer

To play a stagger animation only on heavy hits, compare the event damage with the threshold in an Action Condition. Add more conditions to the same group when the action also depends on target state. Test both a passing and a failing case in Play Mode.

Set up the condition tree​

Open the event's Game Event Behavior and turn on Enable Conditions under Action Condition. Use + Condition to add a comparison or + Group to combine several checks.

Condition tree with its enable toggle, groups, and comparisons

An AND group requires every check to pass. An OR group passes when any check does. Groups can contain other groups. This rule requires an enemy below half health and a hit that is either critical or fire damage.

AND
├── TargetHealthRatio < 0.5
├── IsEnemy == true
└── OR
├── IsCritical == true
└── DamageType == Fire

Check the indentation of the OR group in the tree. Keep both damage checks together and leave the health and team checks in the outer AND group.

An OR group nested inside an AND group

A condition in the event window gates the Event Action list. A condition in the Receiver Inspector gates that component's callback. A condition on a Flow Graph connection controls whether that connection runs.

Choose comparison sources​

Select a source for each side of a comparison, then choose an operator that works with those value types.

Four data sources available on comparison nodes

SourceValue
Event ArgumentThe current event payload, including fields or properties selected through a member path. For sender events, start from Sender or Argument.
Scene TypeA configured scene object reference and its members, such as health, difficulty, or workflow state.
RandomA value drawn from a number range or configured list.
ConstantA fixed value or a list for In List.

Use an object field for a reference you can assign in the scene. For a different runtime instance on each raise, pass the values the rule needs in the event payload.

Add a probability check​

Choose a floating-point Random range from 0 to 1, then compare it with a Constant of 0.3 using < for a pass rate of about 30%.

Range settings for the Random source

If the rule also needs a fixed type or threshold, add those comparisons to the same AND group.

Fixed-value field for the Constant source

Numeric checks can use ==, !=, >, <, >=, and <=. Text checks include Contains, Starts With, and Ends With. Use In List to check membership. Confirm the value types and available operators in the Inspector.

Verify conditions on Mono and IL2CPP​

The Editor and Mono can evaluate unbaked conditions. Some paths cache compiled expression delegates. Member reads, random draws, and the number of checks can still affect execution cost.

Before building an IL2CPP Player, run Bake AOT Conditions under Game Event System > Tools & Utilities and let Unity compile the generated code. Bake again after changes to a scene, Prefab, or condition.

An enabled IL2CPP condition without a valid generated entry logs an error and fails. Trigger a passing case and a failing case in the build.

Apply conditions to callbacks​

Drop rare loot​

Pass the enemy type in the death event. Use In List to match Boss or Elite, then use an OR group to check player luck or the current difficulty rank.

AND
├── Event Argument: EnemyType In List [Boss, Elite]
└── OR
├── Scene Type: LuckModifier > 0.5
└── Scene Type: DifficultyRank >= 2

Advance a movement tutorial​

Read the current step and completion flag from the tutorial component. Pass the action type and duration in the event payload. Put all four checks in one AND group.

AND
├── Scene Type: TutorialComplete == false
├── Scene Type: CurrentStep == Movement
├── Event Argument: ActionType == Move
└── Event Argument: Duration > 1.0

Unlock score achievements​

Give each achievement its own Receiver on the same score event. Both Receivers can require at least 10000 points and check their own unlock flags. The timed achievement also requires a timer below 300 seconds.

Apply bonus fire damage​

Combine the event payload, scene properties, and a random check in an AND group. Bind the bonus damage method so it runs when the hit is fire damage, resistance is low, the difficulty rank qualifies, and the probability check passes.

AND
├── Event Argument: DamageType == Fire
├── Scene Type: FireResistance < 50
├── Scene Type: DifficultyRank >= 2
└── Random (0.0, 1.0) < 0.3

Use the included conditional-event demo to inspect data sources and verify the results of a group.

Configured condition tree in the conditional-event demo

See condition tree configuration and data sources