Skip to main content

States

States let you save different looks of an object and switch between them. Use them for a light switch, a door, a highlight or a product in several colours.

A state is a saved copy of the object's settings: where it stands, its colour, whether it is visible, which animation is selected. Switch to a state, and the object takes that look again.

When to use a state​

You wantUse
A light switch: on and offstates
A door: closed, open, lockedstates
A product in three coloursstates
A character walking along a routeanimation
Something that changes by a calculated amounta patch or a script

A simple rule: a fixed set of named situations is a job for states. Anything that changes continuously is a job for animation.

Create states​

  1. Select the object.
  2. In the inspector, click + new component and choose States. The first state, Default, saves the object as it is now.
  3. Click + add state. The new state is selected.
  4. Change the object: move it, recolour it, hide it. The selected state saves your changes as you go.
  5. Repeat steps 3 and 4 for each state you need.

To preview a state, click it in the list.

While a state is selected, your edits go into it

Editing the object changes the selected state, not the object itself. This is what you want while you build states. But if you forget a state is selected, your change may seem to "not stick" after you switch.

Switch between states​

In an event, use the Set state step. Pick the state and, if you like, a duration and an easing.

With a duration, the change is smooth. The object glides from where it is to the saved look instead of jumping. You get an animation without making one.

Switch fromHow
An eventthe Set state step
A patchthe set_states node
A scriptwrite activeStateId on the States component

React to a switch​

Two triggers fire on the object whose state changed:

TriggerFires when
State activethe object entered the state you picked
State inactivethe object left that state

Each event watches one state, which you choose in its State field. So one object can react differently to each state. For example, a door can show one sign when it opens and another when it closes, with no conditions.

Only the object itself gets these triggers

A state change does not reach the object's parents, unlike a tap.

Change a few things without a state​

Sometimes you want "like now, but red" without making a whole state. Use the Override properties step. It applies a few values once, like a temporary state. It has the same duration and easing settings.

Use it for a quick highlight on hover or a flash when something is hit. Keep real states for the situations the object actually has.

What a state saves​

A state saves the object's components. Position, rotation, scale, material, visibility and the rest all switch together.

A state belongs to one object

It does not save the object's children. To switch a group, give each object its own states. Then switch them all from one event: the step's Target object field takes a list.

Things to watch for​

  • A state left selected in the editor takes your edits. If an object keeps going back to an old look, check which state is selected.
  • States and animation on the same object conflict with each other. Use one or the other.
  • Removing a component also removes it from every state.
  • If the selected state no longer exists, the first state is used.

Next: Patches — logic you build from nodes.