TechnologiesSwiftUI

WorldScalingBehavior struct

iOSmacOStvOSwatchOSvisionOS✓ renders

Specifies the scaling behavior a window should have within the world.

How it works

WorldScalingBehavior describes how SwiftUI scales the model content of a RealityView as it is placed in the surrounding world. In spatial apps, content rendered at a fixed point size can appear too large up close or too small at a distance; the behavior tells the system whether to keep that content at a constant apparent size for the viewer or to let it scale naturally with real-world distance. Reach for it whenever you embed RealityKit content in a window or volume and need predictable, legible sizing across viewing positions.

  1. Choose a behavior with the type's static values

    WorldScalingBehavior is a value type exposing named cases you select rather than construct. The example binds let behavior: WorldScalingBehavior = .dynamic, requesting that content adapt its scale as the viewer's distance changes instead of being pinned to one fixed size.

  2. Apply it with realityViewWorldScalingBehavior()

    You don't place WorldScalingBehavior in the view tree directly; you hand it to the realityViewWorldScalingBehavior(_:) view modifier, which configures the scaling policy for any RealityView in that subtree. The example highlights this entry point with .realityViewWorldScalingBehavior(.dynamic), the call you'd attach to the RealityView showing your 3D content.

  3. Scope it to the RealityView subtree

    The behavior flows down through the environment, so the modifier governs the RealityView it wraps and any nested reality content beneath it. Placing it on the spatial container — the role filled here by the surrounding VStack standing in for that container — keeps the scaling rule attached to exactly the content you intend to size.

  4. Pick the policy that matches your content

    Distance-aware values like .dynamic let WorldScalingBehavior recompute scale as the viewer moves, which suits content meant to feel anchored in the room. A fixed policy instead holds a constant apparent size for UI-like or always-legible content, so the choice of value is how you express your intent.

Try it — Change let behavior: WorldScalingBehavior = .dynamic (and the matching .realityViewWorldScalingBehavior(.dynamic) label) to a fixed scaling value to see content hold one apparent size regardless of viewer distance.

Example & preview

Press Run live & edit to compile it in your browser — then edit the Swift on the left and the preview re-renders live.

WorldScalingBehavior.swift
struct WorldScalingBehaviorDemo: View {
    let behavior: WorldScalingBehavior = .dynamic

    var body: some View {
        VStack(spacing: 12) {
            Image(systemName: "arrow.up.left.and.arrow.down.right.circle")
                .font(.system(size: 44))
                .foregroundStyle(.tint)
            Text("World Scaling Behavior")
                .font(.headline)
            Text("Applied to a RealityView so content scales with viewer distance:")
                .font(.caption)
                .foregroundStyle(.secondary)
                .multilineTextAlignment(.center)
            Text(".realityViewWorldScalingBehavior(.dynamic)")
                .font(.system(.footnote, design: .monospaced))
                .padding(8)
                .background(.quaternary, in: RoundedRectangle(cornerRadius: 8))
        }
        .padding()
    }
}
Live preview
World Scaling Behavior Applied to a RealityView so content scales with viewer distance: .realityViewWorldScalingBehavior(…
World Scaling Behavior Applied to a RealityView so content scales with viewer distance: .realityViewWorldScalingBehavior(…
swift → lexer → parser → sema → uiir → canvas Open in Studio ↗
What's new in SwiftUI 27 →