Play the USDZ animation in RealityView

I have a USDZ model called 'GooseNModel' in the visionOS App project. I'm sure that this model contains an animation, so I wrote the following code to display the model with animation:

import SwiftUI
import RealityKit

RealityView{ content in
    if let GooseNModel = try? await Entity(named: "GooseNModel"),
       let animation = GooseNModel.availableAnimations.first {
        GooseNModel.playAnimation(animation)
        content.add(GooseNModel)
    }
}

But when I ran it, I found that it did not contain animation as I imagined, but a static model. How to solve it?

The following will work.

https://github.com/tokufxug/VisionOSRealityViewEntityAnimation

https://1planet.co.jp/tech-blog/applevisionpro-oneplanet-realityview-entity-animation-01

@sadaotokuyama

I found that this problem is not a problem with the code, but a problem with the USDZ model, because when I use the code you gave me to display the USDZ model you provided on GitHub, I can play the animation normally, but when I use the same code to display my own model, it does not It can play animations. I hope you can tell me how to solve it, thank you!

@lijiaxu Will animations play in RCP, Reality Converter, RealityKit on iOS, or AR Quick Look?

Then, take a look at the following documentation to see if your USDZ file will play animations without problems in RealityKit.

https://developer.apple.com/documentation/realitykit/creating-usd-files-for-apple-devices

https://developer.apple.com/documentation/realitykit/validating-usd-files

Play the USDZ animation in RealityView
 
 
Q