Skip to content
Bit Quirky Round Trip
Visual Scripting

Search documentation

All topics and APIs

Close returns focus to Search.

What are you looking for?

Try a common topic or enter a complete API identifier.

Browse the reference instead

Esc closes · Tab reaches results · Enter opens the focused link

v0.89.0
Menu

Switch on a state

Read one switch arm per enemy state and see exactly which calls each state makes.

Patrolling, stunned, and defeated are three different answers to one question: what should this enemy do in its current state?

An enemy state change must update several components together. A growing chain of conditions can obscure which calls belong to which state. EnemyStateMachine.ApplyState puts each answer in a named switch arm.

  • One enum selects among several distinct behaviors.
  • Each known state owns a short sequence of calls.
  • Adding a state should create a visible place to implement it.
The ApplyState switch with Patrolling, Stunned, and Defeated arms.
Figure 1. Each switch arm carries the calls for one EnemyState value.

The current Platformer source is:

C#
private void ApplyState()
{
switch (CurrentState)
{
case EnemyState.Patrolling:
SetPatrolEnabled(true);
SetBodyColliderEnabled(true);
break;
case EnemyState.Stunned:
// Reserved hook (R6): movement and harm are off, but the enemy is still present.
SetPatrolEnabled(false);
break;
case EnemyState.Defeated:
SetPatrolEnabled(false);
SetBodyColliderEnabled(false);
ApplyDefeatedVisual();
break;
}
}
  1. Open EnemyStateMachine.ApplyState in Graph View.

  2. Find the switch node and read its selector. The CurrentState pill feeds an EnemyState value into the switch.

  3. Follow the Patrolling arm. It enables patrol and the body collider, then stops at the arm’s break.

  4. Follow Stunned. It disables patrol and leaves the enemy present. This arm has one call in the current sample.

  5. Follow Defeated. It disables patrol, disables the body collider, and applies the defeated visual before breaking.

  6. Compare the arms side by side. The switch chooses one arm for the current value; execution does not fall through into the next arm.

Adding one more step to the Stunned arm, for example disabling the body collider while stunned, changes only that case:

An entirely new enum value would need its own switch arm. Keep that arm complete so the graph does not suggest that another case will finish its work.

When it goes wrong

SymptomCheckFix
Two states appear to run in sequence.Look for the break at the end of each switch arm.End each independent arm before the next case begins.
A new enum value has no visible behavior.Compare EnemyState values with the switch arm labels.Add an arm for the new state and connect its state-specific calls.
Defeated enemies still collide.Follow the Defeated arm to SetBodyColliderEnabled.Keep the false literal on that call in the Defeated arm.
Full-size image