4 min read

Entity.write(to:)

Stylized illustration of a melting cube with axis indicators and a ring around it. It mimics a 3D viewfinder

Reality Composer from macOS (not Pro) was quietly sunset not too long ago

Aside from being a graphical editor that allowed for basic scene setup, it also had other great utilities, such as cross-platform preview and some popular features that allowed for creating interaction with triggers and events. 

Reality Composer used a file format with the extension .rcproject, which, after compiling, produced a file with the extension .reality (as in RealityKit file). This type of file has surfaced in various places, like some AR experiences for the WWDC websites, as well as some other great pieces like Ride transit with Apple Pay in AR and For All Mankind: Time Capsule, and, more recently, if you dig deep enough, you can find it is used on the visionOS environments too.

Finder snapshot inspecting the contents of the White Sands Environment, codenamed "Wolf". The primary combined scene titled "Wolf.reality" has been selected. Preview images, textures, audio, and various .plist files can all be found in the package.
White Sands Environment Assets Data Structure

I'm still not sure why this format is necessary at all, as the .usd format should be enough without the need to be wrapped in a .reality, but there could be intellectual property reasons, some extra configuration or behind-the-scenes optimizations that I'm not aware of. But anyways, on the software side, don't get me wrong: I love its successor (Reality Composer Pro), and I've seen firsthand how important graphical editor tools like this are in a company's pipeline. And now, with the most recent updates, we are gaining back some of the beloved missing features.

Back to the file format, regardless of whether we used .rcproject or the current SPM packages, we never had an API for generating .reality files on runtime; everything happened automagically at compile time, which was practical but limited. With visionOS 2, this is about to change, as Entity instances are getting a way to write their content to disk at runtime, enter Entity.write(to:)

try await myEntity.write(to: .temporaryDirectory)

Not much control yet on the results or phases, but it gets the job done

This is significant because it not only allows for simpler exchange of content and state, it unlocks exciting use cases and tools (like debuggers). There is also a counterpart process that supports partial file loading in the under ReferenceComponent, which means that richer loading strategies are now possible (think of game levels loading), as well as frictionless social sharing/consumption of user-generated content (without the loops required for building USDZ files, for example).

someOtherEntity.components.set(
  ReferenceComponent(
    named: "MyEntity",
    loadingPolicy: .onDemand))

if let myEntity = someOtherEntity.findEntity(named: "MyEntity") {
  try await ReferenceComponent.loadReference(at: myEntity)
}

Overall, seemingly minor details can have a significant impact on the evolution of this platform and its future experiences, and the closer we look at what is going to be delivered, the more clear this claim becomes. To use an analogy, picture a world where video could only be watched in real time until there was a way to share it and watch it again later. Imagine what that would mean.


Apple Pay - New York Transit
Traveling around NYC is fast and easy with Apple Pay. Just tap your iPhone or Apple Watch and ride — no need to use Face ID or Touch ID.
“For All Mankind: Time Capsule,” an augmented reality experience, now in the App Store
Available today, “For All Mankind: Time Capsule” is a new augmented reality (AR) experience that brings the world of the Apple TV+ series “For All Mankind” into the homes of fans.
Quick Look Gallery - Augmented Reality - Apple Developer
Embed Quick Look views in your apps and websites to let users see incredible detailed renderings in 3D or AR.