Illustrated scientist next to a Rive state-machine graph crackling with blue lightning.

4 Steps To Build Your First Rive State Machine

Build a clickable on-off switch in Rive and learn how timelines, transitions, and a trigger work together. You can follow along in the Rive editor without writing code or using any course files.

By School of Motion5 min readRive

You’ve animated a switch from off to on. Great. Now make it wait until someone clicks. Then make it go back when they click again. That’s the difference between an animation you watch and an interaction you control.

A Rive state machine decides which animation plays and when to switch to another. You’ll build a toggle from scratch with two looks, one click listener, and no code or course files. By the end, the same spot on the switch will turn it on and off, and the switch will stay where you left it until the next click.

1. Give The Switch Two States: Off And On

Open a new Rive file. In Design mode, use the shape tools to draw a rectangle for the track and a smaller ellipse for the knob. Make the ellipse circular and round the track’s corners in the Inspector. Place the knob inside the left end of the track. Name the shapes Track and Knob in the Hierarchy so you can find them later. Leave room for the knob to slide to the right without changing the track’s size or position.

Before you touch the timeline, decide what each state looks like. Off is a gray track with the knob on the left. On is a colored track with the knob on the right. The change in position makes the two states distinguishable even without color.

Check: You can point to where the knob belongs in each state, and the same track will be clickable in both.

2. Put Each Look On Its Own Timeline

Switch to Animate mode. In the Animations panel, rename the existing timeline Off. If you don’t have a timeline yet, click + next to the timeline tabs and choose Timeline. At frame zero, select Knob and use the key button beside its X position in the Inspector. Then select the track’s fill and key its gray color at the same frame.

Right-click Off in the Animations panel, choose Duplicate, and rename the copy On. At frame zero in On, move the knob to the right and change the track to your accent color. Make sure both changes update the keys at frame zero. Both timelines should key the same properties: knob X position and track fill color.

You don’t need to animate the slide here. Each timeline holds a pose. The state machine will blend between the two poses, so you only have to decide where the knob starts and where it lands.

Check: Select each timeline at frame zero. Off should show gray and left; On should show color and right. If both look the same, check which timeline you edited and whether the values were keyed.

3. Connect The States And Tell Them When To Move

Select the artboard’s state machine in Animations and drag Off and On from the Animations panel onto the graph. Each becomes a state that plays its timeline. To draw a transition, hover near the edge of the state you want to leave and drag its connector to the destination. Connect Entry → Off, then Off → On and On → Off. If Rive already connected Entry to Off, keep that arrow rather than adding another.

Now give both directions something to wait for. In the Data panel, click Add View Model Property next to ViewModel1, choose Trigger, and name it toggle. A trigger is a one-time signal, not a value that stays on or off. The active state is what remembers where the switch is.

Leave Entry → Off unconditional. Select Off → On, click + next to Conditions, and choose the toggle View Model property. Repeat for On → Off. On both of those arrows, leave Exit Time unchecked and set Duration to 150 ms as a starting point. Exit Time makes a transition wait for its current timeline to reach a point; Duration controls how long the blend itself takes.

Check: Play the state machine. It should land on Off and stay there. If it flips on its own, check that neither arrow between Off and On is missing its condition.

4. Wire Up The Click And Test Both Directions

Stop playback and select Track in the Hierarchy. In Animations, click the listeners icon next to the state machine, then click + and choose View Model Change. In the listener settings, confirm Track is the Target and set Listen to to Click. In the action below the graph, choose toggle as the property and set it to Fire. Targeting the stationary track, not the moving knob, keeps the clickable area in the same place.

Play the state machine again. Click the same spot on the track twice, leaving a beat between clicks. The first click should slide the knob right and change the color. The second should slide it left and restore gray. Click outside the track once to check that nothing happens.

If nothing moves: Make sure you’re playing the state machine, not the Off or On timeline. Then check the listener target, the Fire action, and the condition on the outgoing arrow. If it only works once: Check that On → Off exists and listens for the same toggle trigger.

All-Access

Keep Building Rive Interactions

If you want a guided path from your first Rive timeline to an interaction you can hand off, start with Rive Academy Kickstart. The course covers the animation tools, working with multiple timelines, and building and testing interactions with the state machine.

Explore Rive Academy Kickstart

Frequently Asked Questions

Do I Need To Know How To Code To Build This?

No. You can build and preview the whole switch in the Rive editor. If it controls a real preference on a website or in an app, the host application still needs to update and save that preference.

Why Use A Click Instead Of A Hover?

A switch should stay put when the pointer moves away. A Click listener also responds to taps, whereas hover isn’t a reliable way to switch a setting on a touch screen.

Can I Make The Switch Snap Instead Of Slide?

Yes. Set Duration to zero on both transitions. Keep the same poses, trigger, and listener. The switch still works; it just jumps between looks instead of blending.

How Do I See Which State Rive Is Playing?

Open Console above the state machine graph while you test. Look for the transition and state changes after each click. If the graph changes states but the artwork doesn’t change, look at your timeline keys before rebuilding the listener.

Is This Ready To Use As A Website Control?

It’s a visual prototype, not a finished accessible control. If you ship it as a real switch, make sure users can operate it with a keyboard and that assistive technology can tell whether it’s on or off. The animated knob should reflect the actual setting, not be the only record of it.