# AnimationComponent

Class · extends [`Component`](https://api.playcanvas.com/engine/classes/Component.md) · category: Animation (Legacy)

Source: https://github.com/playcanvas/engine/blob/970d89f6d3bc6667f4e1f88153abd6e7e82ed52c/src/framework/components/animation/component.js#L43

The AnimationComponent enables an [Entity](https://api.playcanvas.com/engine/classes/Entity.md) to play back skeletal animations on a model.
It is a legacy component that has largely been superseded by [AnimComponent](https://api.playcanvas.com/engine/classes/AnimComponent.md), which
supports more advanced features such as animation state graphs and blending.

You should never need to use the AnimationComponent constructor directly. To add an
AnimationComponent to an [Entity](https://api.playcanvas.com/engine/classes/Entity.md), use [Entity#addComponent](https://api.playcanvas.com/engine/classes/Entity.md#addcomponent):

```javascript
const entity = new Entity();
entity.addComponent('animation', {
    assets: [animationAsset.id],
    speed: 1
});
```

Once the AnimationComponent is added to the entity, you can access it via the
[Entity#animation](https://api.playcanvas.com/engine/classes/Entity.md#animation) property:

```javascript
entity.animation.speed = 2; // Play the animation at double speed

console.log(entity.animation.speed); // Get the playback speed and print it
```

## Properties

### activate

```ts
activate: boolean = true
```

If true, the first animation asset will begin playing when the scene is loaded.

### skeleton

```ts
skeleton: Skeleton | null = null
```

Get the skeleton for the current model. If the model is loaded from glTF/glb, then the
skeleton is null.

### speed

```ts
speed: number = 1
```

Speed multiplier for animation play back. 1 is playback at normal speed and 0 pauses the
animation.

## Accessors

### animations

```ts
get animations(): {}
set animations(value: {})
```

Gets the dictionary of animations by name.

### assets

```ts
get assets(): (number | Asset<string>)[]
set assets(value: (number | Asset<string>)[])
```

Gets the array of animation assets or asset ids.

### currentTime

```ts
get currentTime(): number
set currentTime(currentTime: number)
```

Gets the current time position (in seconds) of the animation.

### duration

```ts
get duration(): number
```

Gets the duration in seconds of the current animation. Returns 0 if no animation is playing.

### loop

```ts
get loop(): boolean
set loop(value: boolean)
```

Gets whether the animation will restart from the beginning when it reaches the end.

## Methods

### getAnimation

```ts
getAnimation(name: string): Animation
```

Return an animation.

**Parameters**

- `name` (`string`): The name of the animation asset.

**Returns** [`Animation`](https://api.playcanvas.com/engine/classes/Animation.md): An Animation.

### play

```ts
play(name: string, blendTime?: number): void
```

Start playing an animation.

**Parameters**

- `name` (`string`): The name of the animation asset to begin playing.
- `blendTime` (`number`, optional, default `0`): The time in seconds to blend from the current
  animation state to the start of the animation being set. Defaults to 0.

## Inherited from [Component](https://api.playcanvas.com/engine/classes/Component.md)

- `entity: Entity`
- `system: ComponentSystem`
- `get enabled(): boolean` · `set enabled(value: boolean)`
- `fire(name: string, arg1?: any, arg2?: any, arg3?: any, arg4?: any, arg5?: any, arg6?: any, arg7?: any, arg8?: any): EventHandler`
- `hasEvent(name: string): boolean`
- `off(name?: string, callback?: HandleEventCallback, scope?: any): EventHandler`
- `on(name: string, callback: HandleEventCallback, scope?: any): EventHandle`
- `once(name: string, callback: HandleEventCallback, scope?: any): EventHandle`
