Class · inherits Instance
AnimationTrack
Controls the playback of an animation on an Animator.
About AnimationTrack
Controls the playback of an animation on an Animator. This object
cannot be created, instead it is returned by the
Animator.LoadAnimation method.
Properties 9
Animation
: AnimationReadOnlyNotReplicatedTheAnimationobject that was used to create thisAnimationTrack.The
Animationobject that was used to create thisAnimationTrack. To create anAnimationTrack, you must load anAnimationobject onto anAnimatorusing theAnimator.LoadAnimationmethod.IsPlaying
: booleanReadOnlyNotReplicatedA read-only property that returns true when theAnimationTrackis playing.A read-only property that returns true when the
AnimationTrackis playing.This property can be used to check if an animation is already playing before playing it (as that would cause it to restart). If you want to obtain all playing
AnimationTrackson anAnimatoror aHumanoid, they should useAnimator.GetPlayingAnimationTracksLength
: floatReadOnlyNotReplicatedA read-only property that returns the length (in seconds) of anAnimationTrack. This will return0until the animation has fully loaded and thus may not be immediately available.A read-only property that returns the length (in seconds) of an
AnimationTrack. This will return0until the animation has fully loaded and thus may not be immediately available.When the
AnimationTrack.Speedof anAnimationTrackis equal to1, the animation will takeAnimationTrack.Length(in seconds) to complete.Looped
: booleanSets whether the animation will repeat after finishing. If it is changed while playing the result will take effect after the animation finishes.This property sets whether the animation will repeat after finishing. If it is changed while playing the result will take effect after the animation finishes.
This property defaults to how it was set in the Animation Editor. However, this property can be changed, allowing control over the
AnimationTrackwhile it is running. This property also correctly handles animations played in reverse (negativeAnimationTrack.Speed). After the first keyframe is reached, it will restart at the last keyframe.Priority
: AnimationPrioritySets the priority of anAnimationTrack. Depending on what this is set to, playing multiple animations at once will look to this property to figure out whichKeyframePosesshould be played over one another.This property sets the priority of an
AnimationTrack. Depending on what this is set to, playing multiple animations at once will look to this property to figure out whichKeyframeposes should be played over one another. It usesAnimationPrioritywhich has 7 priority levels:Properly set animation priorities, either through the Animation Editor or through this property, allow multiple animations to be played without them clashing. Where two playing animations direct the target to move the same limb in different ways, the
AnimationTrackwith the highest priority will show. If both animations have the same priority, the weights of the tracks will be used to combine the animations.Speed
: floatReadOnlyNotReplicatedRead-only property that gives the current playback speed of theAnimationTrack.This read-only property gives the current playback speed of the
AnimationTrack. When equal to1, the amount of time an animation takes to complete is equal toAnimationTrack.Length, in seconds.If the speed is adjusted through
AnimationTrack.AdjustSpeed, the actual time it will take a track to play can be computed by dividing the length by the speed. Speed is a unitless quantity.TimePosition
: floatNotReplicatedReturns the position in time in seconds that anAnimationTrackis through playing its source animation. Can be set to make the track jump to a specific moment in the animation.Returns the position in time in seconds that an
AnimationTrackis through playing its source animation. Can be set to make the track jump to a specific moment in the animation, but theAnimationTrackmust be playing to do so. It can also be used in combination withAnimationTrack.AdjustSpeedto freeze the animation at a desired point by setting speed to0.WeightCurrent
: floatReadOnlyNotReplicatedRead-only property that gives the current weight of theAnimationTrack.When weight is set in an
AnimationTrackit does not change instantaneously but moves fromAnimationTrack.WeightCurrenttoAnimationTrack.WeightTarget. The time it takes to do this is determined by thefadeTimeparameter given when the animation is played, or the weight is adjusted.AnimationTrack.WeightCurrentcan be checked againstAnimationTrack.WeightTargetto see if the desired weight has been reached. Note that these values should not be checked for equality with the==operator, as both of these values are floats. To see ifAnimationTrack.WeightCurrenthas reached the target weight, it is recommended to see if the distance between those values is sufficiently small.WeightTarget
: floatReadOnlyNotReplicatedRead-only property that gives the current weight of theAnimationTrack.This read-only property gives the current weight of the
AnimationTrack. It has a default value of1and is set whenAnimationTrack.Play,AnimationTrack.StoporAnimationTrack.AdjustWeightis called. When weight is set in anAnimationTrackit does not change instantaneously but moves fromAnimationTrack.WeightCurrenttoAnimationTrack.WeightTarget. The time it takes to do this is determined by thefadeTimeparameter given when the animation is played, or the weight is adjusted.AnimationTrack.WeightCurrentcan be checked againstAnimationTrack.WeightTargetto see if the desired weight has been reached. Note that these values should not be checked for equality with the==operator, as both of these values are floats. To see ifAnimationTrack.WeightCurrenthas reached the target weight, it is recommended to see if the distance between those values is sufficiently small.
Methods 9
AdjustSpeed
(speed: float = 1) → ()Changes theAnimationTrack.Speedof an animation. A positive value for speed plays the animation forward, a negative one plays it backwards, and0pauses it.This method changes the
AnimationTrack.Speedof an animation. A positive value for speed plays the animation forward, a negative one plays it backwards, and0pauses it.A track's initial speed is set as a parameter in
AnimationTrack.Play. However a track'sAnimationTrack.Speedcan be changed during playback using this method. When speed is equal to1, the amount of time an animation takes to complete is equal toAnimationTrack.Length(in seconds).When is adjusted, then the actual time it will take a track to play can be computed by dividing the length by the speed.
AnimationTrack.Speedis a unitless quantity.AdjustWeight
(weight: float = 1, fadeTime: float = 0.100000001) → ()Changes the weight of an animation, with the optionalfadeTimeparameter determining how long it takes forAnimationTrack.WeightCurrentto reachAnimationTrack.WeightTarget.Changes the weight of an animation, with the optional
fadeTimeparameter determining how long it takes forAnimationTrack.WeightCurrentto reachAnimationTrack.WeightTarget.When weight is set in an
AnimationTrackit does not change instantaneously but moves fromAnimationTrack.WeightCurrenttoAnimationTrack.WeightTarget. The time it takes to do this is determined by thefadeTimeparameter given when the animation is played, or the weight is adjusted.The animation weighting system is used to determine how
AnimationTracksplaying at the same priority are blended together. The default weight is1, and no movement will be visible on anAnimationTrackwith a weight of0. The pose that is shown at any point in time is determined by the weighted average of all thePosesand theAnimationTrack.WeightCurrentof eachAnimationTrack. See below for an example of animation blending in practice. In most cases blending animations is not required and usingAnimationTrack.Priorityis more suitable.GetMarkerReachedSignal
(name: string) → RBXScriptSignalReturns anRBXScriptSignal(event) that fires when a specifiedKeyframeMarkerhas been hit in ananimation.This method returns an
RBXScriptSignal(event) similar to theAnimationTrack.KeyframeReachedevent, except it only fires when a specifiedKeyframeMarkerhas been hit in ananimation. The difference allows for greater control of when the event will fire.To learn more about using this method, see here.
See Also
KeyframeMarkerAnimationTrack, controls the playback of an animation on aHumanoidorAnimationControllerKeyframe, holds thePosesapplied to joints in aModelat a given point of time in an animationKeyframe.AddMarkerKeyframe.RemoveMarkerKeyframe.GetMarkers
GetParameter
(key: string) → VariantReturns the value of a parameter on the animation graph by key. Returns nil if the parameter has not been set.Returns the value of a parameter on the animation graph by key. If the parameter has not been set via
AnimationTrack.SetParameter, this method returns nil.Parameters are used to drive inputs on animation graph nodes. Use this method to read back the current value of a parameter that was previously set with
AnimationTrack.SetParameter.GetParameterDefaults
() → DictionaryReturns a dictionary of parameter values initially set as instance attributes on theAnimationGraphDefinitioninstance used to build the animation graph inside this track.Returns a dictionary of default parameter values defined by the animation graph. This can be used to discover what parameters are available on an animation graph and their initial values.
If the underlying
Animationis not an animation graph, this method returns an empty dictionary.GetTimeOfKeyframe
(keyframeName: string) → doubleReturns the time position of the firstKeyframeof the given name in anAnimationTrack.Returns the time position of the first
Keyframeof the given name in anAnimationTrack. If multipleKeyframesshare the same name, it will return the earliest one in the animation.This method will return an error if it is uses with an invalid keyframe name (one that does not exist for example) or if the underlying
Animationhas not yet loaded. To address this make sure only correct keyframe names are used and the animation has loaded before calling this method.To check if the animation has loaded, verify that the
AnimationTrack.Lengthis greater than zero.Play
(fadeTime: float = 0.100000001, weight: float = 1, speed: float = 1) → ()Plays theAnimationTrack. Once called anAnimationTrackwill play with the specifiedfadeTime, weight and speed.When
AnimationTrack.Playis called the track's animation will begin playing and the weight of the animation will increase from0to the specifiedweight(defaults to1) over the specifiedfadeTime.The speed the
AnimationTrackwill play at is determined by the speed parameter (defaults to1). When the speed is equal to1the number of seconds the track will take to complete is equal to the track'sAnimationTrack.Lengthproperty. For example, a speed of2will cause the track to play twice as fast.The weight and speed of the animation can also be changed after the animation has begun playing by using the
AnimationTrack.AdjustWeightandAnimationTrack.AdjustSpeedmethods.If you want to start the animation at a specific point using
AnimationTrack.TimePosition, it's important the animation is played before this is done.SetParameter
(key: string, value: Variant) → ()Sets a parameter value on the animation graph, driving animation graph node inputs.Sets a parameter value on the animation graph, driving animation graph node inputs. Parameters can be set before or during playback. If set before the animation graph has loaded, the value is stored and applied once the graph is ready.
Non-finite numeric values (NaN, Inf) are sanitized to 0 and produce a warning. Use
AnimationTrack.GetParameterDefaultsto discover what parameters are available and their default values.Stop
(fadeTime: float = 0.100000001) → ()Stops theAnimationTrack.Stops the
AnimationTrack. Once called, the weight of the animation will move towards zero over a length of time specified by the optionalfadeTimeparameter. For example, ifStop()is called with afadeTimeof2, it will take two seconds for the weight of the track to reach zero and its effects completely end. Please note this will be the case regardless of the initial weight of the animation.Usage Notes
After calling
Stop(), subsequent calls toStop()andAdjustWeight()will not work as expected. To adjust a track that's fading out, you must first callPlay()to reset theIsPlayingproperty totrue.It is not recommended to use a
fadeTimeof0in an attempt to override this effect and end the animation immediately forMotor6Dsthat have theirMotor.MaxVelocityset to zero, as this causes the joints to freeze in place. If it must end immediately, ensure theMotor.MaxVelocityofMotor6Dsin your rig are high enough for them to snap properly.
Events 3
DidLoop
AnimationTrack.DidLoop:Connect(function())Fires when anAnimationTrackloops on the next update following the end of the previous animation loop.This event fires whenever a looped
AnimationTrackcompletes a loop, on the next update.Currently it may also fire at the exact end of a non looped animation track but this behavior should not be relied upon.
Ended
AnimationTrack.Ended:Connect(function())Fires when theAnimationTrackis completely done moving anything in the world.Fires when the
AnimationTrackis completely done moving anything in the world, meaning the animation has finished playing, the "fade out" is finished, and the subject is in a neutral pose.You can use this to take action when the animation track's subject is back in a neutral pose that's unaffected by the
AnimationTrackor to clean up theAnimationTrack.Stopped
AnimationTrack.Stopped:Connect(function())Fires when theAnimationTrackfinishes playing. The AnimationTrack might still animate the subject while the animation "fades out". To catch when the AnimationTrack is completely done moving anything in the world, use theAnimationTrack.Endedevent.Fires whenever the
AnimationTrackfinishes playing.This event has a number of uses. It can be used to wait until an
AnimationTrackhas stopped before continuing (for example, if chaining a series of animations to play after each other). It can also be used to clean up anyInstancescreated during the animation playback.
AnimationTrack also has every member of Instance. Deprecated and Roblox-only members are hidden.
Reference text from the Roblox Creator Documentation, licensed CC BY 4.0, reorganized by rbxtoolshub.com · Studio 0.743.0.7431133.