title: Play USDZ animation in RealityKit
body: <p>I spent 2 days trying to understand how to play properly an animation in my RealityKit project.</p>
  <p>I followed many tips from others stackoverflow topics but without success. I know that with RealityKit v2 we can only play the first animation from the usdz file, ok. I'm trying to play the first animation of the &quot;toy_robot_vintage.usdz&quot; delivered by Apple directly in the Reality Composer.</p>
  <p>Here is my complete code :</p>
  <pre><code>func loadModel(named: String, result: ARRaycastResult) {
          
          var usdzToLoad: String = &quot;&quot;
          
          switch named {
          case &quot;ROBOT&quot;:
              usdzToLoad = &quot;toy_robot_vintage.usdz&quot;
          default:
              break;
          }
          
          DispatchQueue.main.async {
              let modelToLoad = try! ModelEntity.loadModel(named: usdzToLoad)
              
              switch named {
              case &quot;ROBOT&quot;:
                  modelToLoad.name = &quot;ROBOT&quot;
              default:
                  break;
              }
              
              let anchor = AnchorEntity(plane: .horizontal, classification: .any, minimumBounds: [0.1, 0.1])
                  anchor.position.y = 0.01
                  anchor.addChild(modelToLoad)
              
              // Create a &quot;Physics&quot; model of the toy in order to add physics mode
              guard let modelEntity = anchor.children.first as? (Entity &amp; HasPhysics)
              else { return }
  
              self.arView.installGestures([.rotation], for: modelEntity)
              
              modelEntity.generateCollisionShapes(recursive: true)
              modelEntity.physicsBody = PhysicsBodyComponent(shapes: [.generateBox(size: .one)],
                                                             mass: 1.0,
                                                             material: .default,
                                                             mode: .kinematic)
  
              self.currentEntity = modelEntity
              self.anchorsEntities.append(anchor)
              
              self.arView.scene.addAnchor(anchor)
              
  //            self.currentEntity!.availableAnimations.forEach { self.currentEntity!.playAnimation($0.repeat()) }
              
              let robotAnimationResource = self.currentEntity?.availableAnimations.first
              
              self.currentEntity!.playAnimation(robotAnimationResource!.repeat(duration: .infinity),
                                               transitionDuration: 1.25,
                                                     startsPaused: false)
          }
  </code></pre>
  <blockquote>
  <p>robotAnimationResource is always nil returning of course a fatal error when I try to play the animation.</p>
  </blockquote>
  <p>Any idea ? Thanks in advance for your help and support.</p>