Verse Play Animation On Character
verse-library
# The animation to play. You CANNOT build an animation_sequence in Verse
# (its constructor is epic_internal) -- it's an editor-imported asset. So the
# slot is an OPTION: pick the asset in the device's Details panel in UEFN,
# and we unwrap it at use with `EmoteAnim?`.
@editable
EmoteAnim : ?animation_sequence = false
# Press to play the animation on the presser's character.
@editable
PlayButton : button_device = button_device{}
# Press to stop the most recent playback.
@editable
StopButton : button_device = button_device{}
# Remember the latest instance so the Stop button can cancel it.
var CurrentAnim : ?play_animation_instance = false
OnBegin<override>()<suspends> : void =
PlayButton.InteractedWithEvent.Subscribe(OnPlayPressed)
StopButton.InteractedWithEvent.Subscribe(OnStopPressed)
# GetFortCharacter and GetPlayAnimationController both <decide>, so they go
# in an `if` together with the option unwrap -- all three must succeed.
OnPlayPressed(Presser : agent) : void =
if:
Anim := EmoteAnim?
Character := Presser.GetFortCharacter[]
Controller := Character.GetPlayAnimationController[]
then:
# Play() returns the instance IMMEDIATELY -- it does not suspend.
# The optional ?params let you re-time and blend the clip.
Instance := Controller.Play(
Anim,
?PlayRate := 1.0, # 1.0 = authored speed
?BlendInTime := 0.2, # ease in over 0.2s
?BlendOutTime := 0.2) # ease out over 0.2s
set CurrentAnim = option{Instance}
Print("Playing animation on the presser's character")