RealityKit AnimationEvents question

How do you watch for animationevents in Swift? I have a move animation which has a duration (timingFunction) of 3 seconds and need to be alerted when the move operation on an Entity is complete.

I need to be altered for: AnimationEvents.PlaybackCompleted. How do you set up this event alert watcher in it's own thread or closure in Swift5.0?

If I understood your question correctly something like this should work:

var targetTransform = entityToAnimate.transform
targetTransform.translation.x += 0.4

let animationPlaybackController = entityToAnimate.move(to: targetTransform, relativeTo: entityToAnimate.parent, duration: 3, timingFunction: .easeOut)

arView.scene.subscribe(to: AnimationEvents.PlaybackCompleted.self, on: entityToAnimate) { [weak self] event in
    if event.playbackController == animationPlaybackController {
        print("Animation completed!")
    }
}
.store(in: &subscriptions)
RealityKit AnimationEvents question
 
 
Q