PlayAnimationAction
An action that plays an animation on the given target entity with a range of playback options.
Declaration
struct PlayAnimationActionOverview
Use this action to initiate the playback of animations in a data-driven way. For example, this action can play an animation group which contains a nested action, which plays another animation with specific playback properties.
This action plays the AnimationResource from theAnimationLibraryComponent on the targetEntity. Add all animations to the animation library component that this action will play, ensuring the name of the animation matches the animationName being supplied.
useParentedControllers is used to determine the playback behavior of the animation this action is playing. Set this to true to control the playback of the animation. Calling methods such as pause() and resume() on the animation playback controller generated from this action will give you control of the animation being played. When the action ends, the animation playback also ends. Set this to false to ensure the animation being played runs independently of the action. This would behave as a one shot animation.
The example below is the animation group that the action will play. This contains a sequence containing a single FromToByAnimation<Transform>, and character animation.
// Create an animation group sequence from a range of animations.
let finalAnimation = try AnimationResource
.group(with: [walkAnimation, moveToAnimation])The example below creates an animation sequence. The final animation in the sequence is an animation generated from the action. This action plays an animation that exist within the targetEntity AnimationLibraryComponent.
// An action which plays an animation, with parented controllers.
let playAnimationAction = PlayAnimationAction(animationName: "finalAnimation",
transitionDuration: 0.2,
useParentedControllers: true)
// Creates an animation from the action.
//
// Parented controllers is active. This ensures the action
// plays the entire length of the animation that is being played.
//
// The parameter `finalAnimationDuration` is set to the length
// of the animation group to play.
let finalPlayAnimation = try AnimationResource
.makeActionAnimation(for: playAnimationAction,
duration: finalAnimationDuration)
// Create a sequence of animations that will play.
//
// The action will play last in the sequence.
let animationSequence = try AnimationResource
.sequence(with: [idleAnimation, startWalkAnimation, finalPlayAnimation])
// Play the sequence animation that will play the action last.
let animationPlaybackController = entity.playAnimation(animationSequence)