# Managing State Machines
How to add, remove, and read state machines in a .lottie package with dotlottie-io.

# Managing State Machines

State machines define interactive behavior for a Lottie animation — states, transitions, and actions that a player uses to control playback in response to input or other events.

For the full structure and semantics of a state machine's JSON, see the [official state machine documentation on dotlottie.io](https://dotlottie.io/spec/2.0/#state-machines).

## Adding a state machine

```javascript
dotlottie.addStateMachine("sm-button", "Button Interaction Logic", JSON.stringify(stateMachineJson));
```

- `id` — a unique identifier for this state machine within the package
- `name` — an optional human-readable display name; pass `null` to omit it
- `jsonData` — the state machine definition as a `Buffer` or JSON string

## Removing and reading state machines

```javascript
dotlottie.removeStateMachine("sm-button"); // throws if not found
dotlottie.getStateMachineJson("sm-button"); // → string | null
dotlottie.stateMachineIds(); // → string[]
```

## Finding which animations a state machine controls

```javascript
dotlottie.animationsUsedByStateMachine("sm-button"); // → string[]
```

This returns every unique animation ID referenced by a `PlaybackState` entry inside the state machine's definition.

Next up: [The Manifest](/docs/tools/dotlottie-io/core-concepts/manifest)
