Autoplay stage metadata not being acknowledged RealityView (RCP Bundle)

VisionPro Question if that’s okay here - I’m finally checking out how to use my wee hand coded USD files in a VisionPro app. The Apple documentation seems to say RealityKit should obey the autoplay metadata, but it doesn’t seem to work. Is the problem with my USDA files, the Swift, or something else?

I can make the animations run with an explicit call to run, but what have I done wrong to get the one cube to autoplay?

import SwiftUI
import RealityKit
import RealityKitContent

struct ContentView: View {

    @State var enlarge = false

    var body: some View {
        VStack {
            //A ModelEntity, not expected to autoplay
            Model3D(named: "cube_purple_autoplay", bundle: realityKitContentBundle)
            //An Entity, actually expected this to autoplay
            RealityView { content in
                if let cube = try? await Entity(named: "cube_purple_autoplay", in: realityKitContentBundle) {
                    print(cube.components)
                    content.add(cube)
                }
            }
            //Scene has one cube that should auto play, one that should not.
            //Neither do, but both will start (as expected) with click.
            RealityView { content in
                // Add the initial RealityKit content
                if let scene = try? await Entity(named: "Scene", in: realityKitContentBundle) {
                    content.add(scene)
                }
            } update: { content in
                // Update the RealityKit content when SwiftUI state changes
                if let scene = content.entities.first {
                    
                    if enlarge {
                        for animation in scene.availableAnimations {
                            scene.playAnimation(animation.repeat())
                        }
                    } else {
                        scene.stopAllAnimations()
                    }
                    let uniformScale: Float = enlarge ? 1.4 : 1.0
                    scene.transform.scale = [uniformScale, uniformScale, uniformScale]
                }
                
               
            }
            .gesture(TapGesture().targetedToAnyEntity().onEnded { _ in
                enlarge.toggle()
            })

            VStack {
                Toggle("Enlarge RealityView Content", isOn: $enlarge)
                    .toggleStyle(.button)
            }.padding().glassBackgroundEffect()
        }
    }
}

No autospin meta data

#usda 1.0
(
    defaultPrim = "transformAnimation"
    endTimeCode = 89
    startTimeCode = 0
    timeCodesPerSecond = 24
    upAxis = "Y"
)

def Xform "transformAnimation" ()
{
    def Scope "Geom"
    {
        def Xform "xform1"
        {
            float xformOp:rotateY.timeSamples = {
               ...
            }
            double3 xformOp:translate = (0, 0, 0)
            uniform token[] xformOpOrder = ["xformOp:translate", "xformOp:rotateY"]

            over "cube_1" (
                prepend references = @./cube_base_with_purple_linked.usd@
            )
            {   
                double3 xformOp:translate = (0, 0, 0)
                uniform token[] xformOpOrder = ["xformOp:translate"]
            }
        }

With autoplay metadata

#usda 1.0
(
    defaultPrim = "autoAnimation"
    endTimeCode = 89
    startTimeCode = 0
    timeCodesPerSecond = 24
    autoPlay = true
    playbackMode = "loop"
    upAxis = "Y"
)

def Xform "autoAnimation"
{
    def Scope "Geom"
    {
        def Xform "xform1"
        {
            float xformOp:rotateY.timeSamples = {
                ...
            }
            double3 xformOp:translate = (0, 0, 0)
            uniform token[] xformOpOrder = ["xformOp:translate", "xformOp:rotateY"]

            over "cube_1" (
                prepend references = @./cube_base_with_purple_linked.usd@
            )
            {
                quatf xformOp:orient = (1, 0, 0, 0)
                float3 xformOp:scale = (2, 2, 2)
                double3 xformOp:translate = (0, 0, 0)
                uniform token[] xformOpOrder = ["xformOp:translate", "xformOp:orient", "xformOp:scale"]
            }
        }
    }
}

Hi, @carlynorama
Questions specific to the Vision Pro and any Apple schemas would be best asked on the Apple Developer forums instead.

I’d also recommend filing feedback at feedbackassistant.apple.com for any issues you encounter like this.

Thank you, I understand and agree about keeping this forum platform agnostic. I did cross post it there.

However, I thought it was maybe on topic here because I actually wasn’t clear if loop/autoPlay were Apple schemas or schemas that Apple was reading in. The animations I wrote were very much not Apple schema specific but yet still detected by the Apple framework. It felt “cross platform interopy”/“implementation best practices” to me for loops and autoplay. I am not confident that it wasn’t my USDA files (that I am writing by hand) that are incorrect.

I’m pretty sure they aren’t correct, actually. Since posting I noticed that in USDView the autoplay file has

Sdf.UnregisteredValue('true') 
Sdf.UnregisteredValue('"loop"')

in the meta data so looks like I got some learning to do about where / how to declare valid variables and Schemas for use in metadata!

When I figure it out / if its not Apple specific I’ll report back. :slightly_smiling_face:

Auto play is an Apple specific thing autoPlay | Apple Developer Documentation

You can find a list of all our custom definitions here USDZ Schemas for AR | Apple Developer Documentation

1 Like