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
print(AnimationTrack.Animation)
IsPlaying
bool
This property returns whether the animation track is running. (Read-only)
Code Samples
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
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
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
AnimationTrack.Priority = Enum.AnimationPriority.Movement
AnimationTrack:Play()
Speed
number
Currently not supported.
Code Samples
TimePosition
number
Currently not supported.
Code Samples
WeightCurrent
number
Currently not supported.
Code Samples
WeightTarget
number
Currently not supported.
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
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)
AdjustWeight
Currently not supported.
Parameters
number
InWeight
number
InFadeTime
Return
void
Code Samples
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
local function OnAnimationEvent()
print("OnAnimationEvent")
end
AnimationTrack:GetMarkerReachedSignal("SomeKeyName"):connect(OnAnimationEvent)
GetTimeOfKeyframe
Currently not supported.
Parameters
string
InName
Return
number
Code Samples
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
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
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
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
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
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
local function OnStopped()
print("The animation has been stopped!")
end
AnimationTrack.Stopped:Connect(OnStopped)
See also
Character AnimationLast updated