Playing Animation using visionOS - Reality Composer Pro - USDZ

I have a usdz model with animation that I can preview in RCP. When I create a new base/example visionOS project in Xcode it's set up to load in the 'Scene" and "Immersive" reality kit content. But my models don't play the animation.

How do I fire off the contained animations in those files?

Is there a code snippet that someone can share that takes into account how the example project is setup?

Hey there! To play a model's animation, you have to store the animation on your model as an Animation Resource and then pass that into the .playAnimation method.

let animScene = try await Entity(named: "anim", in: realityKitContentBundle)
guard let animModel = animScene.findEntity(named: "anim") else { return }
guard let animResource = animModel.availableAnimations.first else { return }
let anim = try AnimationResource.generate(with: animResource.repeat().definition)

animModel.playAnimation(anim)

Make note, you can only play the first available animation on a .usdz file at the moment. If you want to play multiple animations, you have to either load in separate .usdz files that have the animations you want to store as Animation Resources, or create Animation Clips as shown in the WWDC 21 video "Dive into Reality Kit 2"

Playing Animation using visionOS - Reality Composer Pro - USDZ
 
 
Q