4

I've followed the answer in this SO question regarding playing the animation of a USDZ file with the following code:

@IBOutlet var arView: ARView!

override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view.
    
    arView = ARView(frame: self.view.frame)
    self.view.addSubview(arView)
    arView.cameraMode = .nonAR
    let newAnchor = AnchorEntity(world: .zero)
    let newEnt = try! Entity.load(named: "Vintage Toy Robot")
    newAnchor.addChild(newEnt)
    arView.scene.addAnchor(newAnchor)
    
    print(newEnt.availableAnimations)
    
    for anim in newEnt.availableAnimations {
        newEnt.playAnimation(anim.repeat(duration: .infinity), 
                             transitionDuration: 1.25, startsPaused: false)
    }
}

However, the animation does not play, the USDZ file is just static.

Andy Jazz
  • 49,178
  • 17
  • 136
  • 220
narner
  • 2,908
  • 3
  • 26
  • 63

1 Answers1

2

Download robot model with animation from AR Quick Look page. Your code is working. Do not use not-animated robot from Reality Composer library.

let entity = try! Entity.load(named: "toy_robot_vintage.usdz")

And delete these two lines of code (you've got 2 ARViews, it's blocking the animation):

arView = ARView(frame: self.view.frame)
self.view.addSubview(arView)
Andy Jazz
  • 49,178
  • 17
  • 136
  • 220
  • 1
    Oh; yeah that's the one I am using - in the Xcode viewer I can play/pause the model just fine – narner Jan 04 '23 at 22:55