# AnimationTrack

AnimationTrack : `Instance`

## Overview

This object manages the execution of animations applied to an Animator.

It can only be obtained by calling the Animator's LoadAnimation() method.

## Properties

### Animation

`Animation`

This property returns the Animation object set in the AnimationTrack. (Read-only)

#### Code Samples

```lua
print(AnimationTrack.Animation)
```

### IsPlaying

`bool`

This property returns whether the animation track is running. (Read-only)

#### Code Samples

```lua
AnimationTrack:Play()

if AnimationTrack.IsPlaying then
    print("DoSomething")
end
```

### Length

`number`

This property returns the total duration of the animation track in seconds. (Read-only)

#### Code Samples

```lua
print(AnimationTrack.Length)
```

### Looped

`bool`

This property specifies whether the animation automatically loops after completion.

This property must be set before running the animation to work normally. Changing its value during execution may cause the animation to stop and not return to the default animation after it finishes.

#### Code Samples

```lua
AnimationTrack.Looped = true
```

### Priority

`Enum.AnimationPriority`

This property specifies which animation takes precedence when multiple animations are running simultaneously.

Enum.AnimationPriority is divided into seven levels, from the highest, Action4, to the lowest, Core. Properly setting the animation priority ensures smooth blending when multiple animations are played simultaneously.

For example, Setting the AnimationTrack's Priority to Movement immediately stops the animation when a movement action occurs. Conversely, setting it to Action allows the animation to continue playing even during moving.

The default is Action.

#### Code Samples

```lua
AnimationTrack.Priority = Enum.AnimationPriority.Movement

AnimationTrack:Play()
```

### Speed

`number`

This is a read-only property that shows the current playback speed of the AnimationTrack. If you change the playback speed using the AdjustSpeed() method, this property reflects the updated speed.

#### Code Samples

```lua
print(AnimationTrack.Speed)
```

### UpperBodyAnimation

`bool`

This property determines whether the animation is applied only to the upper body when played. When set to true, the animation will affect only the upper body, allowing lower body movements (such as walking or running) to continue while upper body actions are animated.

#### Code Samples

## Methods

### AdjustSpeed

Controls the playback speed of the animation.

The default animation speed is specified when AnimationTrack:Play() is called, but can be modified separately during playback.

#### Parameters

| `number` InSpeed | The playback speed. |
| ---------------- | ------------------- |

#### Return

| `void` |   |
| ------ | - |

#### Code Samples

```lua
local AnimationTrack = Hum:LoadAnimation(Animation)
AnimationTrack:AdjustSpeed(0.3)

AnimationTrack:Play()
wait(1)
-- It can also be modified while the animation is playing.
AnimationTrack:AdjustSpeed(1)
```

### GetMarkerReachedSignal

Returns an event that fires upon reaching a specific marker at a certain keyframe during animation playback.

#### Parameters

| `string` InName | The name of the marker. |
| --------------- | ----------------------- |

#### Return

| `ScriptSignal` | The returned event. |
| -------------- | ------------------- |

#### Code Samples

```lua
local function OnAnimationEvent()
    print("OnAnimationEvent")
end
AnimationTrack:GetMarkerReachedSignal("SomeKeyName"):connect(OnAnimationEvent)
```

### Play

Runs the animation track.

InFadeTime controls how long it takes for the weight to gradually increase as the animation plays, providing a gradual transition effect.

InSpeed lets you scale the playback speed of your animations, making them run faster or slower than the default speed.

#### Parameters

| `number` InFadeTime | The time it takes for the animation weight to increase (The default is 0.1). |
| ------------------- | ---------------------------------------------------------------------------- |
| `number` InWeight   | Currently not supported.                                                     |
| `number` InSpeed    | The playback speed. (The default is 1.)                                      |

#### Return

| `void` |   |
| ------ | - |

#### Code Samples

```lua
local Players = game:GetService("Players")

local Character = Players.LocalPlayer.Character
local Humanoid = Character:WaitForChild("Humanoid")

local Animation = Instance.new("Animation")
Animation.AnimationId = "ovdrassetid://18850100" -- WinAnimation01

local Animator = Humanoid:FindFirstChild("Animator")
local AnimationTrack = Animator:LoadAnimation(Animation)

AnimationTrack:Play()
```

### Stop

Stops the currently playing animation track.

#### Parameters

| `number` InFadeTime | Currently not supported. |
| ------------------- | ------------------------ |

#### Return

| `void` |   |
| ------ | - |

#### Code Samples

```lua
AnimationTrack:Stop()
```

## Events

### DidLoop

This event is executed each time a looping animation track completes a loop.

It occurs immediately after the loop ends in the next update and is not called for non-looping animations.

#### Parameters

#### Code Samples

```lua
AnimationTrack.Looped = true

local function OnLoopAnimation()
    print("The animation looped!")
end
AnimationTrack.DidLoop:Connect(OnLoopAnimation)

AnimationTrack:Play()
```

### Ended

This event is executed when the animation track has finished playing.

It is not called when the loop function is enabled, and is also called when terminated by the Stop() method.

#### Parameters

#### Code Samples

```lua
local function OnEnded()
    print("The animation has ended!")
end
AnimationTrack.Ended:Connect(OnEnded)
```

### KeyframeReached

(Deprecated) This event is executed each time a keyframe with a specified name is reached during animation playback

We recommend using GetMarkerReachedSignal.

#### Parameters

| `string` InKeyframeReached | The keyframe name. |
| -------------------------- | ------------------ |

#### Code Samples

```lua
local function OnKeyframeReached(keyframeName)
    print(keyframeName)
end
AnimationTrack.KeyframeReached:Connect(OnKeyframeReached)
```

### Stopped

This event is executed when the animation track stops playing, as terminated by the Stop() method.

#### Parameters

#### Code Samples

```lua
local function OnStopped()
    print("The animation has been stopped!")
end
AnimationTrack.Stopped:Connect(OnStopped)
```

## See also

{% content-ref url="../../../manual/studio-manual/character/character-animation" %}
[character-animation](https://docs.overdare.com/manual/studio-manual/character/character-animation)
{% endcontent-ref %}
