One Logo Pool Ball
RealityFoundation · IOS API REFERENCE

Scene

class · iOS 13.0+ · SDK 27.1

@MainActor @preconcurrency class Scene

A container that holds the collection of entities that an AR view renders. You don’t create a ``Scene`` instance directly. Instead, you get the one and only scene associated with a view from the ``ARView/scene`` property of an ``ARView`` instance. ![Block diagram showing the scene as a property of an AR view, with anchor entities as the scene’s children.](Scene-1) To add content to the view’s scene, you first create and add one or more ``AnchorEntity`` instances to the scene’s ``RealityKit/Scene/anchors`` collection. Anchors tell RealityKit how to pin virtual content to real world objects, like flat surfaces or images. You then add a hierarchy of other ``RealityKit/Entity`` instances to each anchor to indicate the geometry and behaviors that RealityKit should render at a given anchor point.

Members (18)

method · iOS 13.0+

convexCast

TypeScript
convexCast(convexShape: ShapeResource, fromPosition: SDKHandle, fromOrientation: SDKHandle, toPosition: SDKHandle, toOrientation: SDKHandle, query?: CollisionCastQueryType, mask?: CollisionGroup, referenceEntity?: (Entity) | null): Promise<Array<CollisionCastHit>>
Swift declaration
@MainActor @preconcurrency func convexCast(convexShape: ShapeResource, fromPosition: SIMD3<Float>, fromOrientation: simd_quatf, toPosition: SIMD3<Float>, toOrientation: simd_quatf, query: CollisionCastQueryType = .all, mask: CollisionGroup = .all, relativeTo referenceEntity: Entity? = nil) -> [CollisionCastHit]

Performs a convex shape cast against all the geometry in the scene. - Parameters: - convexShape: The convex shape to cast. - fromPosition: The starting position of `convexShape` relative to `referenceEntity`. - fromOrientation: The starting orientation of `convexShape` relative to `referenceEntity`. - toPosition: The ending position of `convexShape` relative to `referenceEntity`. - toOrientation: The ending orientation of `convexShape` relative to `referenceEntity`. - query: The query type. - mask: A collision mask that you can use to prevent collisions with certain objects. - referenceEntity: An entity that defines the frame of reference. The method returns results relative to this entity. Set to `nil` to use the world space origin `(0, 0, 0)`. - Returns: An array of collision cast hit results. Each hit indicates where the convex shape, starting at a given point and traveling in a given direction, collides with entities in the scene. To retrieve the hit entity from a returned ``CollisionCastHit``, use the ``CollisionCastHit/entity`` property. For objects that intersect the convex shape at its starting position and orientation, the returned collision cast hit result’s ``CollisionCastHit/position`` is `(0, 0, 0)` and the ``CollisionCastHit/normal`` points in the opposite direction of the sweep.

method · iOS 18.0+

findEntity

TypeScript
findEntityId(id: number): Promise<(Entity) | null>
Swift declaration
@MainActor @preconcurrency func findEntity(id: Entity.ID) -> Entity?

Returns `Entity` with the given `Entity.ID` in the `Scene`. - Parameters: - id: `Entity.ID` obtained from `Entity.id` - Returns: `Entity` with the given `Entity.ID`, or `nil` if no such `Entity` is found in the `Scene`. - Note: This method uses efficient mapping from `Entity.ID` to `Entity`, not linear traversal of all Entities in the `Scene`.

method · iOS 13.0+

findEntity

TypeScript
findEntityNamed(name: string): Promise<(Entity) | null>
Swift declaration
@MainActor @preconcurrency func findEntity(named name: String) -> Entity?

Searches the scene’s anchor entity hierarchies for an entity with the given name. The ``Scene/findEntity(named:)`` method conducts a depth-first, recursive search over all of the scene’s entities for one whose ``Entity/name`` property matches the given name. The method returns the first match. Entity names need not be unique. - Parameters: - name: The name of the entity for which to search. - Returns: The first entity found with the given name, or `nil` if none is found.

get · iOS 27.0+

commandQueue

TypeScript
get commandQueue(): Promise<(SDKHandle) | null>
Swift declaration
@MainActor @preconcurrency var commandQueue: (any MTLCommandQueue)? { get }

If this scene uses a MTLCommandQueue for rendering, returns it. You use this command queue for GPU workloads that need consistent ordering relative to RealityKit's scene rendering.

method · iOS 15.0+

performQuery

TypeScript
performQuery(query: EntityQuery): Promise<QueryResult<Entity>>
Swift declaration
@MainActor @preconcurrency func performQuery(_ query: EntityQuery) -> QueryResult<Entity>

Returns all entities of the scene which pass the query. When in ``System/update(context:)-69f86``, call ``SceneUpdateContext/entities(matching:updatingSystemWhen:)`` instead of `performQuery`. This allows the ``System`` to sleep on some platforms when there is no matching component, reducing unnecessary work.

method · iOS 13.0+

removeAnchor

TypeScript
removeAnchor(anchor: SDKHandle): Promise<void>
Swift declaration
@MainActor @preconcurrency func removeAnchor(_ anchor: any HasAnchoring)

Removes the specified anchor from the scene. - Parameters: - anchor: The anchor to remove.

get · iOS 13.0+

synchronizationService

TypeScript
get synchronizationService(): Promise<(SDKHandle) | null>
Swift declaration
@MainActor @preconcurrency var synchronizationService: (any SynchronizationService)? { get set }

The service to use for network synchronization.

set · iOS 13.0+

synchronizationService

TypeScript
setSynchronizationService(value?: (SDKHandle) | null): Promise<void>
Swift declaration
@MainActor @preconcurrency var synchronizationService: (any SynchronizationService)? { get set }

The service to use for network synchronization.

get · iOS 13.0+

id

TypeScript
get id(): Promise<number>
Swift declaration
nonisolated var id: UInt64 { get }

The stable identity of the entity associated with this instance.

get · iOS 13.0+

name

TypeScript
get name(): Promise<string>
Swift declaration
@MainActor @preconcurrency var name: String { get }

A name for the scene.

get · iOS 13.0+

anchors

TypeScript
get anchors(): Promise<Scene_AnchorCollection>
Swift declaration
@MainActor @preconcurrency var anchors: Scene.AnchorCollection { get set }

The collection of anchors contained in the scene.

set · iOS 13.0+

anchors

TypeScript
setAnchors(value: Scene_AnchorCollection): Promise<void>
Swift declaration
@MainActor @preconcurrency var anchors: Scene.AnchorCollection { get set }

The collection of anchors contained in the scene.

method · iOS 13.0+

raycast

TypeScript
raycastFromToQueryMaskRelativeTo(startPosition: SDKHandle, endPosition: SDKHandle, query?: CollisionCastQueryType, mask?: CollisionGroup, referenceEntity?: (Entity) | null): Promise<Array<CollisionCastHit>>
Swift declaration
@MainActor @preconcurrency func raycast(from startPosition: SIMD3<Float>, to endPosition: SIMD3<Float>, query: CollisionCastQueryType = .all, mask: CollisionGroup = .all, relativeTo referenceEntity: Entity? = nil) -> [CollisionCastHit]

Performs a ray cast against all the geometry in the scene for a ray between two end points. The method ignores entities that lack a ``CollisionComponent``. The ``CollisionCastHit/normal`` property on returned result objects contains the surface normal at the point of intersection with the entity’s collision shape. The following are some details to keep in mind. * The ray needs to fully intersect a primitive for a hit to be detected. In particular, it is not enough for the ray to precisely tangent or end at the primitive's surface. This becomes especially important when ray casting against primitives that are far away from the ray origin. * Due to numerical imprecision, it may be necessary to use a slightly longer ray length than your desired maximum distance in order to ensure that a full intersection occurs with your target primitive. Moreover, the length of the ray needs to be a positive finite number that is smaller than ``greatestFiniteMagnitude``. - Parameters: - startPosition: The start position of the ray relative to `referenceEntity`. - endPosition: The end position of the ray relative to `referenceEntity`. - query: A query type. - mask: A collision mask that you can use to prevent collisions with certain objects. - referenceEntity: An entity that defines the frame of reference. The method returns results relative to this entity. Set to `nil` to use the world space origin `(0, 0, 0)`. - Returns: An array of collision cast hit results. Each hit indicates where the ray, starting at `startPosition` and ending at `endPosition`, hit a particular entity in the scene.

method · iOS 13.0+

raycast

TypeScript
raycastOriginDirectionLengthQueryMaskRelativeTo(origin: SDKHandle, direction: SDKHandle, length?: number, query?: CollisionCastQueryType, mask?: CollisionGroup, referenceEntity?: (Entity) | null): Promise<Array<CollisionCastHit>>
Swift declaration
@MainActor @preconcurrency func raycast(origin: SIMD3<Float>, direction: SIMD3<Float>, length: Float = 100, query: CollisionCastQueryType = .all, mask: CollisionGroup = .all, relativeTo referenceEntity: Entity? = nil) -> [CollisionCastHit]

Performs a ray cast against all the geometry in the scene for a ray of a given origin, direction, and length. The method ignores entities that lack a ``CollisionComponent``. The ``CollisionCastHit/normal`` property on returned result objects contains the surface normal at the point of intersection with the entity’s collision shape. The following are some details to keep in mind. * The ray needs to fully intersect a primitive for a hit to be detected. In particular, it is not enough for the ray to precisely tangent or end at the primitive's surface. This becomes especially important when ray casting against primitives that are far away from the ray origin. * Due to numerical imprecision, it may be necessary to use a slightly longer ray length than your desired maximum distance in order to ensure that a full intersection occurs with your target primitive. Moreover, the length of the ray needs to be a positive finite number that is smaller than ``greatestFiniteMagnitude``. - Parameters: - origin: The origin of the ray relative to `referenceEntity`. - direction: The direction of the ray relative to `referenceEntity`. - length: The length of the ray relative to `referenceEntity`. - query: A query type. - mask: A collision mask that you can use to prevent collisions with certain objects. - referenceEntity: An entity that defines the frame of reference. The method returns results relative to this entity. Set to `nil` to use the world space origin `(0, 0, 0)`. - Returns: An array of collision cast hit results. Each hit indicates where the ray, starting at a given point and traveling in a given direction, hit a particular entity in the scene.

get · iOS 18.0+

timebase

TypeScript
get timebase(): Promise<_CoreMedia_CMTimebase>
Swift declaration
@MainActor @preconcurrency var timebase: CMTimebase { get }

The default timebase for the scene, useful for driving custom times managed by the user which are derived from the scene time.

method · iOS 13.0+

addAnchor

TypeScript
addAnchor(anchor: SDKHandle): Promise<void>
Swift declaration
@MainActor @preconcurrency func addAnchor(_ anchor: any HasAnchoring)

Adds an anchor to the scene’s list of anchors. - Parameters: - anchor: The anchor to add.

method · iOS 18.0+

pixelCast

TypeScript
pixelCastFromTo(startPosition: SDKHandle, endPosition: SDKHandle): Promise<(PixelCastHit) | null>
Swift declaration
@MainActor @preconcurrency func pixelCast(from startPosition: SIMD3<Float>, to endPosition: SIMD3<Float>) async throws -> PixelCastHit?

Performs a ray cast against all the geometry in the scene for a ray between two end points. The method ignores entities that lack a ``ModelComponent`` with a valid mesh. - Parameters: - startPosition: The start position of the ray relative to the scene. - endPosition: The end position of the ray relative to the scene. - Returns: A `PixelCastHit`. The hit indicates where the ray, starting at `startPosition` and ending at `endPosition`, hit a particular entity in the scene.

method · iOS 18.0+

pixelCast

TypeScript
pixelCastOriginDirectionLength(origin: SDKHandle, direction: SDKHandle, length?: number): Promise<(PixelCastHit) | null>
Swift declaration
@MainActor @preconcurrency func pixelCast(origin: SIMD3<Float>, direction: SIMD3<Float>, length: Float = 100) async throws -> PixelCastHit?

Performs a ray cast against all the geometry in the scene for a ray of a given origin, direction, and length. The method ignores entities that lack a ``ModelComponent`` with a valid mesh. - Parameters: - origin: The origin of the ray relative to the scene. - direction: The direction of the ray relative to the scene. - length: The length of the ray relative to the scene. - Returns: A `PixelCastHit`. The hit indicates where the ray, starting at a given point and traveling in a given direction, hit a particular entity in the scene.

Skipped declarations

4 declarations were excluded from these bindings. Each reason comes from the generator or the iOS SDK compiler.

Scene.subscribe(to:on:_:)

Passing a Swift type itself is not supported.

Scene.publisher(for:on:)

Passing a Swift type itself is not supported.

Scene.subscribe(to:on:componentType:_:)

Passing a Swift type itself is not supported.

Scene.publisher(for:on:componentType:)

Passing a Swift type itself is not supported.

All RealityFoundation types →