Press to Perform: Driving a Skeletal Mesh from Verse
verse-library
skel_performer_device := class(creative_device):
# The skeletal-mesh performer. Choose its mesh + animation in the editor.
@editable
Statue : animated_mesh_device = animated_mesh_device{}
# One button cycles through Play -> Pause -> Reverse.
@editable
ControlButton : button_device = button_device{}
# Which state the next press should APPLY. Starts at "play".
var Step : int = 0
OnBegin<override>()<suspends> : void =
ControlButton.InteractedWithEvent.Subscribe(OnPress)
# Each press advances the transport: Play, then Pause, then PlayReverse,
# then back to Play. The Animated Mesh device remembers its own playhead,
# so Pause freezes mid-animation and Play resumes from there.
OnPress(Presser : agent) : void =
case (Step):
0 =>
Statue.Play()
Print("Animated Mesh: Play")
1 =>
Statue.Pause()
Print("Animated Mesh: Pause (frozen on current frame)")
_ =>
Statue.PlayReverse()
Print("Animated Mesh: PlayReverse")
# Advance, wrapping 0 -> 1 -> 2 -> 0. Verse has no `%` operator; the
# built-in Mod[] is the failable modulo (it fails only on divide-by-zero,
# which can't happen here). The if simply re-binds Step to the result.
if (Next := Mod[Step + 1, 3]):
set Step = Next