1

I am loading toy-robot-vintage.usdz (to be sure, I've checked the other models too) from apple website into my project.

In the quick look you can play the animation for that robot. But after I load the model, and successfully placed it into the scene, I want to print the list of available animations with the button. It always prints an empty array

Forgive me for the force unwrap:

let robot = try! ModelEntity.load(named: "robot")

Then, I print the available animations (after the model was fully loaded).

@objc private func multipurposeButtonTapped() {
        print(robot.availableAnimations)
        print(robot.availableAnimations.count)
    }

But the result is always the same:

enter image description here

I've checked Apple developer forum and found that question been asked a year ago, sadly with no response. The one annotation was to change .loadModel method to .load, but that did not solve the issue in my case.

What could be wrong here?

Thank you.

Jakub Gawecki
  • 801
  • 2
  • 6
  • 14

1 Answers1

1

ModelEntity works fine. It prints just ONE animation by default.

do {
    let robot = try ModelEntity.load(named: "toy_robot")

    print(robot.availableAnimations)            /*  [AnimationResource]     */
    print(robot.availableAnimations.count)      /*  1                       */
    print(robot.availableAnimations[0].name!)   /*  global scene animation  */

} catch {
    print("Failed to load a robot asset")
}

To add more animations to a model, use:

@MainActor func store(in: Entity)

P. S.

As @maxxfrazer said, Entity works too.

let robot = try Entity.load(named: "toy_robot")

enter image description here

Andy Jazz
  • 49,178
  • 17
  • 136
  • 220