Verse Library verse

28 Building Keyframes With Code

Builds keyframes from segments, applies them to a movement component, and loops animation playback.

extracted-snippets/documentation/en-us/fortnite/create-platformer-02-moving-entities-using-animations-in-scene-graph-in-unreal-editor-for-fortnite/28-building-keyframes-with-code.verse

# Source URL: https://dev.epicgames.com/documentation/en-us/fortnite/create-platformer-02-moving-entities-using-animations-in-scene-graph-in-unreal-editor-for-fortnite
# Local doc:  epic-docs/documentation/en-us/fortnite/create-platformer-02-moving-entities-using-animations-in-scene-graph-in-unreal-editor-for-fortnite.md
# Section:    Building Keyframes with Code
# Construct and play an animation from an array of animation segments.
ConstructAndPlayAnimations<private>(InSegments:[]segment, AnimationPlayback:keyframed_movement_playback_mode)<suspends>:void=
var ShouldBreakOut:logic = false
# If this is a oneshot animation, break out of loop after it plays once.
if (oneshot := oneshot_keyframed_movement_playback_mode[AnimationPlayback]):
set ShouldBreakOut = true
# Position this entity in the correct starting position.
if:
KeyframedMovementComponent := Entity.GetComponent[keyframed_movement_component]
StartingTransform :=
FirstSegment := InSegments[0].SegmentStartPosition?.GetGlobalTransform()
then:
Entity.SetGlobalTransform(StartingTransform)
# Sleep for initial pause.
Sleep(InitialPauseSeconds)
# Build the array of keyframes to play the animation from.
var Keyframes:[]keyframed_movement_delta = array{}
for:
Index -> Segment:InSegments
SourceEntity := Segment.SegmentStartPosition?
DestinationEntity := InSegments[Index + 1].SegmentStartPosition?
do:
Easing := Utilities.TryGetValueOrDefault(Segment.EasingFunction, DefaultEasingFunction)
Duration := Segment.AnimationDuration
# Construct each keyframe and add it to the array.
if:
Keyframe := ConstructKeyframe[SourceEntity, DestinationEntity, Easing, Duration]

Sign in free to read the full source 🌴

This Verse Library file is members-only. Create a free account to view the complete source and download the .verse file.

Sign in with Discord

Comments

    Sign in to vote, comment, or suggest an edit. Sign in