Okay, I'm missing something fundamental here. I want to create a scene for visionOS with a continuously rotating cube. I set up my scene and register a System to do the rotation updates.
When I run on the simulator or headset, the first 20 updates happen pretty quickly, then slow to a stop, and the cube stops rotating. If I grab the volume handle and move the volume around, the scene updates and the cube rotates as long as I'm moving it.
How do I get the cube to rotate continuously without interacting with the volume?
import SwiftUI
import RealityKit
struct ContentView: View {
var body: some View {
VStack {
RealityView { content in
// Create a shiny red cube entity
let cube = MeshResource.generateBox(size: [0.3, 0.3, 0.3])
let matl = SimpleMaterial(color: .red, isMetallic: false)
let cubeEntity = ModelEntity(mesh: cube, materials: [matl])
cubeEntity.name = "cube"
content.add(cubeEntity)
// Register the "SpinSystem" system to rotate it
SpinSystem.registerSystem()
}
}
}
}
// A System to incrementally spin the cube every frame
class SpinSystem : System {
var theta: Float = 0
var count: Int = 0
required init(scene: RealityFoundation.Scene) {}
func update(context: SceneUpdateContext) {
count += 1
print("update \(count)")
if let cubeEntity = context.scene.findEntity(named: "cube") {
theta += 0.01
cubeEntity.transform.rotation = simd_quatf(angle: theta, axis: simd_float3(1, 0, 0))
}
}
}
update 1
update 2
cannot add handler to 0 from 1 - dropping
update 3
update 4
update 5
update 6
update 7
cannot add handler to 0 from 1 - dropping
update 8
update 9
...
update 21
update 22
update 23