A container that holds the collection of entities rendered by an AR view.


class Scene


You don’t create a Scene instance directly. Instead, you get the one and only scene associated with a view from the 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.

To add content to the view’s scene, you first create and add one or more AnchorEntity instances to the scene’s 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 Entity instances to each anchor to indicate the geometry and behaviors that RealityKit should render at a given anchor point.


Identifying the Scene

var name: String

A name for the scene.

var id: ObjectIdentifier

The stable identity of the entity associated with self.

var id: UInt64

The stable identity of the scene.

typealias Scene.ID

A type of unique identifier used for a scene.

Adding and Removing Anchors

var anchors: Scene.AnchorCollection

The collection of anchors contained in the scene.

func addAnchor(HasAnchoring)

Adds an anchor to the scene’s list of anchors.

func removeAnchor(HasAnchoring)

Removes the specified anchor from the scene.

struct Scene.AnchorCollection

A collection of anchor entities.

Finding Entities

func findEntity(named: String) -> Entity?

Searches the scene’s anchor entity hierarchies for an entity with the given name.

Detecting Intersections

func raycast(origin: SIMD3<Float>, direction: SIMD3<Float>, length: Float, query: CollisionCastQueryType, mask: CollisionGroup, relativeTo: Entity?) -> [CollisionCastHit]

Performs a convex ray cast against all the geometry in the scene for a ray of a given origin, direction, and length.

func raycast(from: SIMD3<Float>, to: SIMD3<Float>, query: CollisionCastQueryType, mask: CollisionGroup, relativeTo: Entity?) -> [CollisionCastHit]

Performs a convex ray cast against all the geometry in the scene for a ray between two end points.

struct CollisionCastHit

A hit result of a collision cast.

enum CollisionCastQueryType

The kinds of ray and convex shape cast queries that you can make.

struct CollisionGroup

A bitmask used to define the collision group to which an entity belongs, and with which it can collide.

Synchronizing Entities Between Devices

var synchronizationService: SynchronizationService?

The service to use for network synchronization.

protocol SynchronizationService

An interface that enables entity synchronization among a group of local peers.

Getting and Sending Events

func publisher<E>(for: E.Type, on: EventSource?) -> Scene.Publisher<E>

Generates a publisher for events of the specified type.

struct Scene.Publisher

A publisher for the given event type in the scene.

enum SceneEvents

Events the scene triggers.

enum AnimationEvents

Events triggered by the RealityKit animation system.

enum AudioEvents

Events associated with audio playback.

enum CollisionEvents

Events associated with collisions.

protocol Event

A type that can be sent as an event.

protocol EventSource

A type on which events can be published and subscribed.

Comparing Scenes

static func == (Scene, Scene) -> Bool

Indicates whether two scenes are equal.

static func != (Scene, Scene) -> Bool

Indicates whether two scenes are not equal.

func hash(into: inout Hasher)

Hashes the essential components of the scene by feeding them into the given hash function.

var hashValue: Int

The hashed value of the scene.


Conforms To

See Also

The Entity Component System

class Entity

An element of a RealityKit scene to which you attach components that provide appearance and behavior characteristics for the entity.

protocol Component

A representation of a geometry or a behavior that you apply to an entity.

protocol Resource

A shared resource you use to configure a component, like a material, mesh, or texture.


Beta Software

This documentation contains preliminary information about an API or technology in development. This information is subject to change, and software implemented according to this documentation should be tested with final operating system software.

Learn more about using Apple's beta software