---
url: /api/kiln/functions/animationGraph.md
---
[Kiln API](../../index.md) / [kiln](../index.md) / animationGraph

# Function: animationGraph()

```ts
function animationGraph<S, P, T>(spec): AnimationGraph;
```

Defines an animation state graph as data, checked when it is made:

```ts
export const HeroAnim = animationGraph({
  initial: 'idle',
  params: { speed: 0 },
  triggers: ['attack'],
  states: { idle: {}, run: { events: [{ frame: 1, name: 'footstep' }] }, attack: { loop: 'once' } },
  transitions: [
    { from: 'idle', to: 'run', when: { speed: { gt: 0.1 } } },
    { from: 'run', to: 'idle', when: { speed: { lte: 0.1 } } },
    { from: '*', to: 'attack', trigger: 'attack' },
    { from: 'attack', to: 'idle', exitTime: 1 },
  ],
})
```

## Type Parameters

| Type Parameter | Default type |
| ------ | ------ |
| `S` *extends* `string` | - |
| `P` *extends* `Record`<`string`, `number` | `boolean`> | `object` |
| `T` *extends* `string` | `never` |

## Parameters

| Parameter | Type |
| ------ | ------ |
| `spec` | [`AnimationGraphSpec`](../interfaces/AnimationGraphSpec.md)<`S`, `P`, `T`> |

## Returns

[`AnimationGraph`](../interfaces/AnimationGraph.md)
