Animation scripts

IntermediateProgrammer Animations are controlled using scripts. AnimationComponent to an entity and set up its parameters in Game Studio. The AnimationComponent class is designed to be used mainly from a script. The more useful properties include:

Note

AnimationComponent. Set up animations.

Use the pre-built AnimationStart script

AnimationStart script. You can use this script as a template to write your own animation scripts. AnimationStart script:

  • Asset View (bottom pane by default), click Add asset.
  • Add asset > Scripts > Animation start.
  • Create script. Save script. Reload assemblies. -

    Example animation script

    This sample script assigns a simple animation to a character based on its walking speed.
    1. using Xenko.Engine;namespace AdditiveAnimation{ public class AnimationClipExample : SyncScript { public float MovementSpeed { get; set; } = 0f; private float walkingSpeedLimit = 1.0f; // Assuming the script is attached to an entity which has an animation component private AnimationComponent animationComponent; public override void Start() { // Cache some variables we'll need later animationComponent = Entity.Get<AnimationComponent>(); animationComponent.Play("Idle"); } protected void PlayAnimation(string name) { if (!animationComponent.IsPlaying(name)) animationComponent.Play(name); } public override void Update() { if (MovementSpeed <= 0) { PlayAnimation("Idle"); } else if (MovementSpeed <= walkingSpeedLimit) { PlayAnimation("Walk"); } else { PlayAnimation("Run"); } } }}

    Override the animation blend tree

    First-person shooter, Third-person platformer and Top-down RPG, which use some advanced techniques, are examples of how to do this. For more information, see custom blend trees.

    See also

  • Scripts
  • Animation index
  • Import animations
  • Animation properties
  • Set up animations
  • Preview animations
  • Additive animation
  • Procedural animation
  • Custom blend trees
  • Model node links
  • custom attributes