How to scale RealityView content when a Volume is resized
Prevent content from getting clipped when users resize volumes.
Overview
This example is based on prior work by Drew Olbrich. I suggest you this article first.
This example makes some assumptions to keep things simple.
- We have a volume with a default size of 1000 points on all sides
- We have a scene in Reality Composer Pro with a scale of 1.0
- We want to scale the scene relative to the volume size
A volume with a default size
struct Garden032App: App {
var body: some Scene {
WindowGroup {
ContentView()
}
.windowStyle(.volumetric)
.defaultSize(width: 1000, height: 1000, depth: 1000)
}
}I adapted the function provided by Drew into an extension on Entity. We pass in a RealityViewContent and a GeometryProxy3D, with the option to provide a Size3D as well. This function uses the frame of the geometry proxy to calculate a new scale. We need to convert from the SwiftUI coordinate space to RealityKit.
Side note: Notice the scaleDifference condition? If you watch the console you will notice that RealityView updates anytime we move the volume, not just when we resize it. Something about GeometryProxy3D is triggering this update. I added this condition so we only apply the scale when it has actually changed. You can remove or customize this if it doesn’t work for your scenes.
extension Entity {
@MainActor func scaleWithVolume(
_ realityViewContent: RealityViewContent,
_ geometryProxy3D: GeometryProxy3D,
_ defaultVolumeSize: Size3D = Size3D(width: 1.1, height: 1.1, depth: 1.1)
) {
let scaledVolumeContentBoundingBox = realityViewContent.convert(geometryProxy3D.frame(in: .local), from: .local, to: .scene)
let scaleX = scaledVolumeContentBoundingBox.extents.x / Float(defaultVolumeSize.width)
let scaleY = scaledVolumeContentBoundingBox.extents.y / Float(defaultVolumeSize.height)
let scaleZ = scaledVolumeContentBoundingBox.extents.z / Float(defaultVolumeSize.depth)
let newScale: SIMD3<Float> = [scaleX, scaleY, scaleZ]
self.scale = newScale
}
}Usage is simple. We can call this function on an entity at the root of our volume content.
struct ContentView: View {
/// A top level entity that will be scaled with the volume. Only the root view will be added to this
@State private var volumeRootEntity = Entity()
var body: some View {
GeometryReader3D { proxy in
RealityView { content in
content.add(volumeRootEntity)
/// A root view for the graveyard content. All other entities will be added to this.
guard let baseRoot = try? await Entity(named: "Scene", in: realityKitContentBundle) else { return }
baseRoot.name = "TableScene"
baseRoot.position = [0, -0.45, 0] // Move this down to the bottom of the volume
volumeRootEntity.addChild(baseRoot, preservingWorldTransform: true)
} update: { content in
volumeRootEntity.scaleWithVolume(content, proxy)
print("Update closure called. current scale: \(volumeRootEntity.scale.x)")
}
.debugBorder3D(.white)
}
}
}Video Demo
Video demo showing content scaled based on volume size
This is one way to handle this issue, but not the only way. I’ve found that this solution has the best results for my projects. It handles all the edge cases mentioned in the article by Drew.
Support our work so we can continue to bring you new examples and articles.

Follow Step Into Vision