LoadAnimation
This function is deprecated in favor of using Animator/LoadAnimation directly (the Animator may be created while editing or at runtime). For more information, see this announcement.
For thread safety, this property is not safe to read in an unsynchronized thread.
This function loads an Animation onto an AnimationController, returning an AnimationTrack that can be used for playback.
How to load an Animation
The following code can be used to load an Animation onto an AnimationController.
local animationTrack = animationController:LoadAnimation(animation)
animationTrack:Play()
Should I load an Animation on the client or server?
In order for AnimationTracks to replicate correctly, it’s important to know when they should be loaded on the client (via aLocalScript) or on the server (via a Script).
If an Animator is a descendant of a Humanoid or AnimationController in a Player’s Player/Character|Character then animations started on that Player’s client will be replicated to the server and other clients.
If the Animator is not a descendant of a player character, its animations must be loaded and started on the server to replicate.
The Animator object must be initially created on the server and replicated to clients for animation replication to work at all. If an Animator is created locally, then AnimationTracks loaded with that Animator will not replicate.
Both Humanoid/LoadAnimation and AnimationController/LoadAnimation will create an Animator if one does not already exist. When calling LoadAnimation from LocalScripts you need to be careful to wait for the Animator to replicate from the server before calling LoadAnimation if you want character animations to replicate. You can do this with WaitForChild(“Animator”).
See also
- Using the Animation Editor, explore this powerful built-in plugin for creating custom animations
- Using Animations in Games, learn how to add pre-built and custom animations to your game
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
|
|
The |
Returns
| Return Type | Summary |
|---|---|
Code Samples
Using an AnimationController to animation non-player objects
This code sample demonstrates how an AnimationController can be used in place of a Humanoid for non player character objects.
A basic rig is loaded using InsertService and the default Humanoid is replaced with an AnimationController. An AnimationTrack is then created and played.