We shipped an update to the functionality of play_animation_controller interface to support custom animation on player characters with 41.10.
The interface now allows you to play a custom animation sequence on player or NPC characters with synchronous Play() function or the asynchronous PlayAndAwait() function. You can also set blend times and subscribe to various events in Verse.
Below is sample code to play a random custom animation sequence on the player character upon interacting a Button device.
using { /Fortnite.com/Devices }
using { /Fortnite.com/Characters }
using { /Fortnite.com/Animation/PlayAnimation }
using { /Verse.org/Assets }
using { /Verse.org/Random }
using { /Verse.org/Simulation }
# Plays a custom animation on a player when they interact with a button.
# UEFN Setup:
# 1. Place this device in your level.
# 2. Assign a button_device to the TriggerButton property.
# 3. Assign your imported animation_sequence assets to the AnimationSequences property.
player_animation_demo_device := class(creative_device):
# Assign a button device in the UEFN editor
@editable
TriggerButton : button_device = button_device{}
# Assign your custom animation sequence asset in the UEFN editor
# Click the '+' button to add slots and pick your animations.
@editable
AnimationSequences : []animation_sequence = array{}
OnBegin<override>()<suspends>:void =
TriggerButton.InteractedWithEvent.Subscribe(PlayAnimationOnButtonInteracted)
# Play a random animation when a player interacts with the button
PlayAnimationOnButtonInteracted(Target : agent) : void =
# only proceed if AnimationSequences has valid animations
if (AnimationSequences.Length > 0):
RandomIndex := GetRandomInt(0, AnimationSequences.Length - 1)
if:
SelectedAnim := AnimationSequences[RandomIndex]
AnimationController := Target.GetFortCharacter[].GetPlayAnimationController[]
then:
AnimationController.Play(SelectedAnim)
You can combine PutInStasis usage to freeze the player movement along with the animation API usage to have better control to the player character animation and not have it interrupted by player’s input.
Furthermore, when using asset reflection, you can also play custom animations on the player character using the animation module.
To learn further how to play character animations in Verse, please check the Calling Animations with Verse section with further explanations and more code snippets.
For more information about the API, see the play_animation_controller interface documentation.