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.

Jandi
61k19 gold badges166 silver badges263 bronze badges
asked Jan 4, 2023 at 22:11

1 Answer 1

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)
answered Jan 4, 2023 at 22:53
Sign up to request clarification or add additional context in comments.

1 Comment

Oh; yeah that's the one I am using - in the Xcode viewer I can play/pause the model just fine

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.