Contents

write(_:to:options:)

Exports an array of entities as separate scenes within a single RealityKit file.

Declaration

nonisolated(nonsending) static func write(_ scenes: [Entity], to url: URL, options: Entity.WriteOptions = WriteOptions()) async throws

Parameters

  • url:

    The location URL in the file system where you want to save the .reality file.

  • options:

    Options for writing the Reality file, such as texture compression settings.

Discussion

This method generates a file with a .reality suffix, automatically setting its compatibility with other systems based on all the entity tree contents. The entities and their children may contain components or assets that can require the resulting RealityKit file to be compatible with system versions between:

  • iOS 18 or later

  • macOS 15 or later

  • visionOS 2 or later

Elements of the entities array must have a non-empty name property. Each name must be unique within the array to allow unambiguous scene loading.

After writing, individual scenes can be loaded using the init(contentsOf:withName:) initializer with the entity’s name as the scene identifier.

Logs with the prefix [RealityKit File Compatibility Info] will be posted to the console whenever a component or asset requires a compatibility adjustment.

See Also

Writing an entity to a file