How to update RealityKit entities when volume viewpoint changes
Listen for changes to viewpoint with onVolumeViewpointChange.
Starting in visionOS 2, volumes support viewpoints. With no work from us, features like ornaments, tab controls, and toolbars will automatically change orientation to face the user. What if we want the entities in our scene to do the same thing?
If your volume contains a Model3D, then take a look at the example code in the docs. This example is for entities in RealityView.
Each volume has four viewpoints represented as a SquareAzimuth. These are front, back, left, and right. We can use onVolumeViewpointChange to listen for change, then update entities in our scene as needed.
.onVolumeViewpointChange { _, newValue in
// Get a rotation value from the squareAzimuth
let newRotation = simd_quatf(newValue.squareAzimuth.orientation)
// Set the orientation of content in our scene
subject.orientation = newRotation
}For a more complex example, check out the BOT-anist example project. This uses an extension on Entity to create animations from the SquareAzimuth values.
visionOS simulator video showing a skull turning to face a user on view point change
Example Code
struct ContentView: View {
@State var subject = Entity()
var body: some View {
RealityView { content in
guard let scene = try? await Entity(named: "Scene", in: realityKitContentBundle) else { return }
content.add(scene)
scene.position.y = -0.2
guard let skull = scene.findEntity(named: "Skull") else { return }
subject = skull
}
.onVolumeViewpointChange { _, newValue in
// Get a rotation value from the squareAzimuth
let newRotation = simd_quatf(newValue.squareAzimuth.orientation)
// Set the orientation of content in our scene
subject.orientation = newRotation
}
}
}Sample code is available in Garden24 in the Step Into Example Projects repo.
Support our work so we can continue to bring you new examples and articles.
Download the Xcode project with this and many more examples from Step Into Vision.
Some examples are provided as standalone Xcode projects. You can find those here.

Follow Step Into Vision