State Machines

10–15 minutes · Intermediate

Timelines create motion. State machines create behavior. A state machine answers: which animation should play right now?

State machines are the bridge between animation and interaction. They make the difference between a clip that plays once and an animation that responds to the user.

Core concepts

State

A state represents a specific animation or behavior. Examples: Idle, Walk, Hover, Pressed, Loading.

Transition

A transition defines when movement between states is allowed.

Idle → Walk
Walk → Idle

Input

Inputs provide information that can influence state changes. Types:

  • Boolean: isHovered, isPressed, isLoading. Stays true or false until something changes it.
  • Trigger: fires once to start a transition, then clears itself.
  • Number: a value from 0 to 1. Transitions can’t read a number, and the editor marks these inputs as runtime v1 skips. See Known Limitations.

How transitions work

  • Entry state: the machine starts here. Select a state and tap Set as Entry State to change it. Without a choice, it’s the first state.
  • Conditions: a transition can check whether a bool has a value (Bool Equals), a trigger fired (Trigger Fired) or the state has run for a number of seconds (Has Exit Time). All conditions on a transition must be true.
  • No conditions: a transition without conditions never runs.
  • Priority: Kineto checks the transitions leaving the current state in the order you created them, and the first match wins. You can’t reorder them, so delete and recreate a transition to move it to the end. Avoid relying on this: make rules exclusive where you can.
  • Blending: a transition blends for its Duration, 0.15 seconds by default, with its Easing. A duration of 0 is an instant cut.
  • During a blend: no other transition can start. The machine checks conditions again when the blend ends. A trigger that fires during a blend is lost.
  • Returning: a state doesn’t return on its own when its clip ends. Add a transition back, with a condition such as a bool that turned false or Has Exit Time.

Button example

A button with three states and two bool inputs, isHovered and isPressed. Default is the entry state.

From To Condition
Default Hover isHovered is true
Hover Default isHovered is false
Hover Pressed isPressed is true
Pressed Hover isPressed is false

Each state has one way forward and one way back, so the order doesn’t matter. If the pointer leaves while pressed, the button goes through Hover back to Default.

Character example

A character with Idle, Walk and Run, driven by your app’s speed value. A transition can’t compare numbers, so your app turns the speed into two bools, and the states can’t overlap:

Speed isMoving isRunning State
0 false false Idle
Above 0, below your threshold true false Walk
At your threshold or above true true Run

Idle is the entry state.

Order From To Condition
1 Idle Walk isMoving is true
2 Walk Idle isMoving is false
3 Walk Run isRunning is true
4 Run Idle isMoving is false
5 Run Walk isRunning is false

Order matters for transitions 4 and 5. When the character stops from a run, both bools turn false, and both transitions match. Because you created Run → Idle first, it wins. If it came second, the character would go through Walk.

Your app sets the bools from its speed, for example in Swift:

try player.setBool(speed > 0, input: "isMoving", in: machine)
try player.setBool(speed >= runThreshold, input: "isRunning", in: machine)

Building a state machine

  1. Create your clips in the Animate tab.
  2. Switch to the Logic tab and tap Create State Machine.
  3. Tap Create State and choose a clip. For each next state, open the Clips tab at the bottom and tap a clip, or drag it onto the graph.
  4. Select the state that should come first and tap Set as Entry State.
  5. In the Inputs tab at the bottom, tap Add Input and choose a type.
  6. Select a state and drag the + handle on its right edge to another state. This creates a transition.
  7. With the transition selected, add a condition under Conditions. Without one, it never runs.
  8. Add the transition back to the first state.
  9. Test each path in Test Preview.

Example: Cody’s wink

Cody, the bear on the Kineto homepage, is a real project with a small state machine. Tap one of his eyes and he winks.

States and clips

The machine has three states. Idle is the entry state and plays a 5-second idle clip. Wink and Wink right each play a clip of half a second.

The Logic tab with three states named Idle, Wink and Wink right, joined by four transitions, a small Test Preview at the top and the clips Wink left, Idle and Wink right at the bottom.
Cody's state machine: Idle, plus a wink for each eye.

Inputs

Two boolean inputs say which eye is being pressed: tapped-left-eye and tapped-right-eye. Open the Inputs tab at the bottom to see them. You can also flip them by hand there to test a transition.

The Inputs tab with two boolean inputs, tapped-left-eye and tapped-right-eye, and the inspector for the Idle state with its linked clip and four transitions.
Two boolean inputs, and the Idle state with its transitions.

Transitions

Four transitions connect the states, each with one condition, an Ease curve and a blend of 0.15 seconds.

From To Condition
Idle Wink tapped-left-eye is true
Wink Idle tapped-left-eye is false
Idle Wink right tapped-right-eye is true
Wink right Idle tapped-right-eye is false

The inputs decide when Cody returns, not the clip. If an input stays true after the half-second clip, Cody stays in the Wink state, with his eye open again.

The transition from Idle to Wink selected. The inspector shows the condition tapped-left-eye equals True, a blend of 0.15 seconds and the easing option Ease.
The transition from Idle to Wink runs when tapped-left-eye is true.

Connect taps to inputs

The inputs still need something to change them. Cody has a target region over each eye, set to Reacts to taps. Pressing the region turns the input on, and releasing turns it off. See Targets & Constraints.

Cody with a target region selected over his left eye. The inspector shows left-eye-target set to Reacts to taps, with Catches touch on and two reactions, Up and Down, that toggle tapped-left-eye.
A region over the eye turns taps into input changes.

Test it full screen

The small Test Preview in the Logic tab has a button to open it full screen. There you can test on the whole screen, with these tools:

  • Hit areas draws everything a finger can touch, colored by what it drives
  • Runtime shows the current state and clip
  • Inputs lets you flip inputs by hand
  • Event Log lists what your taps and drags do

Press play to start the machine.

The fullscreen Test Preview with Cody, two highlighted hit areas over his eyes, a legend of hit area types, the inputs and an empty event log.
The fullscreen preview draws what a finger can touch.
The fullscreen Test Preview, paused during the wink with hit areas hidden. Cody's left eye is closed to a thin line and his right eye is open. The runtime panel shows state Wink and clip Wink left, and the input tapped-left-eye is switched on.
With tapped-left-eye on, the machine moves to Wink and plays Wink left. The wink is quick, so this frame is paused.

State machines and export

State machines become more valuable when animations leave the editor. Your app can drive inputs and allow animations to respond to user actions and application state. This is one of the key differences between a simple animation and an interactive animation.

See iOS Playback and Web Playback for how to set Cody’s inputs from code.

Common mistakes

Nothing changes

Check that the transition has a condition, because a transition without one never runs. Then check that the input really gets the expected value.

The wrong transition runs

Two transitions leaving the same state can match at once. The one you created first wins. Make the rules exclusive, or recreate the transitions in the order you want.

The animation gets stuck in a state

A state doesn’t return on its own. Check that a transition leads back, and that its condition can become true.

The graph becomes confusing

Reduce the number of states and simplify transitions. Complexity compounds fast.

Best practices

  • Use clear state names: Idle not State1
  • Keep transitions simple at first
  • Start with two or three states
  • Test inputs frequently during construction
  • Build interaction gradually