Aego Русский

Animator

Plays the states of an animation controller and blends between them when its parameters change. The graph, the blends, root motion and gameplay events run on fixed steps, so replays match at any frame rate.

component animation.Animator
On this page

Art Studio

Character animation Art Studio lessons

Try it

Advance an Animator state

A script sets the controller's Speed parameter to select Run. The separate Animator Speed field starts at 0, holding the state time.

Change Animator Speed from 0 to 8. The real Run clip advances and the runner turns orange after its state time moves. Reset holds it again.

Starts the scene; open the example parameters to experiment.
Open in AegoDownload example project
Scene3 nodes
Runner
Transform
position[0, 0]rotation0scale[1, 1]
Sprite Renderer
spriteTextureasset("ae900000000000000000000000000b00")tintColor#7dd3fcffsizeVec2[5, 5]filterenumnearest
Animator
controllerAnimControllerasset("ae900000000000000000000000000b20")playOnStartbooltruespeedfloat0timeDomainenumgamerootMotionenumnonerootScaleVec2[1, 1]
Floor
Transform
position[0, 3]rotation0scale[1, 1]
Sprite Renderer
spriteTextureasset("ae900000000000000000000000000010")tintColor#4b5563ffsizeVec2[12, 0.2]
Camera
Transform
position[0, 0]rotation0scale[1, 1]
Camera 2D
zoomfloat40clearColorColor#111827ffscaleenumfitVirtualvirtualVec2[960, 540]activebooltrue
Scriptmain.aes
package demo

// The graph's Speed parameter selects Run independently of the Animator's
// playback Speed field. The color marks actual advancement in that state.
script RunIndicator {
    var advanced bool

    func FixedUpdate(dt float) {
        a := node.Get<Animator>()
        a.SetFloat("Speed", 3)
        if a.State == "Run" && a.Time > 0.05 {
            advanced = true
        }
        if advanced {
            node.Get<SpriteRenderer>().Tint = Color{1, 0.2, 0.1, 1}
        }
    }
}

Fields

NameTypeDefaultDescription
ControllerAnimControllernone

Controller with the states, parameters and transitions.

Play On Startbooltrue

Enters the entry state when Play starts.

Speedfloat1

Multiplies the speed of every state; 1 is normal speed.

Time Domainenumgame

game follows game time and pauses with it; unscaled runs in real time while paused, for presentation only.

one of: game, unscaled
Root Motionenumnone

What the root track moves: none ignores it, toMotion moves the node through Motion 2D so walls stop it, toTransform sets its position.

one of: none, toMotion, toTransform
Root Fallbackboolfalse

toMotion moves the transform instead when the node has no Motion 2D.

Root ScaleVec2(1, 1)

Multiplies root motion in the node's parent space; set X to -1 while the character faces left.

Runtime state

Values the component has while the game runs. They are not saved with the scene.

NameTypeDefaultDescription
Statestring""

Current state.

Timefloat0

Seconds in the current state.

Progressfloat0

Time in the current state divided by the length of its clip; 1 is one full clip.

Blendingboolfalse

Whether a transition is blending.

Methods

CrossFade method

func (Animator) CrossFade(state string, seconds float)

Blends into a state over some seconds, starting on the next fixed step.

GetBool method

func (Animator) GetBool(name string) bool

Reads a bool or trigger parameter.

GetFloat method

func (Animator) GetFloat(name string) float

Reads a float parameter.

GetInt method

func (Animator) GetInt(name string) int

Reads an int parameter.

IsState method

func (Animator) IsState(state string) bool

Reports whether the animator is in a state; during a blend that is the state it blends into.

Play method

func (Animator) Play(state string)

Switches to a state on the next fixed step, without a blend.

ResetTrigger method

func (Animator) ResetTrigger(name string)

Clears a trigger that has not fired yet.

SetBool method

func (Animator) SetBool(name string, value bool)

Sets a bool parameter; transitions read it on the next fixed step.

SetFloat method

func (Animator) SetFloat(name string, value float)

Sets a float parameter.

Example

anim.SetFloat("Speed", math.Abs(motion.Velocity.X))

SetInt method

func (Animator) SetInt(name string, value int)

Sets an int parameter.

SetTrigger method

func (Animator) SetTrigger(name string)

Sets a trigger for the next fixed step; a transition that uses it, or the end of that step, clears it.

StateName method

func (Animator) StateName(index int) string

Returns the name of a state index, as StateEntered and StateExited report it.

Signals

Event signal

signal Event(id int, payload float)

Runs when a state reaches an event of its clip; during a blend the state's event policy decides which side reports.

StateEntered signal

signal StateEntered(state int)

Runs when the animator enters a state, at the start of the transition.

StateExited signal

signal StateExited(state int)

Runs when a state stops playing, at the end of the transition.

Script events

Scripts on a node with this component receive these events from the Animation module.