RealityKit Basics: Loading Entities from Data

We can load Entities from a block of Data, which we can retrieve remotely.

Overview

visionOS 26 brings a new way to load entities: Entity(from: data). See What’s new in RealityKit from WWDC for a minimal example. This makes it easier to host our assets on a server and load them in our app at runtime.

We need three things a minimum to make this work.

// A URL to the file
private let remoteURL = URL(string: "https://stepinto.vision/wp-content/uploads/2025/10/Earth.usdz")!
// Loading the URL into Data
URLSession.shared.data(from: remoteURL)
// Using the loaded Data
Entity(from: data) 

See also

fileprivate struct LoadingExample01: View {
    private let remoteURL = URL(string: "https://stepinto.vision/wp-content/uploads/2025/10/Earth.usdz")!
    var body: some View {
        RealityView { content in
            if let (data, _) = try? await URLSession.shared.data(from: remoteURL) {
                if let entity = try? await Entity(from: data) {
                    content.add(entity)
                }
            }
        }
        .realityViewLayoutBehavior(.fixedSize)
    }
}

Let’s improve this a bit by adding some state. We can show a progress indicator while the asset is loading. On success we show the file name. If we run into an error we can show the error text.

// A slightly improved example that shows a progress indicator while loading. We can capture an error and display the file name on success.
// In production we would want to expand this to an enum to capture all possible states
fileprivate struct LoadingExample02: View {

    @State private var isLoading = false
    @State private var response : URLResponse?
    @State private var fileName: String = ""
    @State private var errorString: String?

    private let remoteURL = URL(string: "https://stepinto.vision/wp-content/uploads/2025/10/Earth.usdz")!

    var body: some View {
        RealityView { content in
            do {
                isLoading = true
                let (data, response) = try await URLSession.shared.data(from: remoteURL)
                fileName = response.suggestedFilename ?? "unknown"
                let entity = try await Entity(from: data)
                content.add(entity)
                isLoading = false
            } catch {
                isLoading = false
                errorString = error.localizedDescription
            }
        }
        .realityViewLayoutBehavior(.fixedSize)
        .ornament(attachmentAnchor: .scene(.bottomFront), ornament: {
            VStack {
                if(isLoading ) {
                    ProgressView()
                } else {
                    // Show the error string if we have one, else show the file name
                    Text("\(errorString ?? fileName)")
                }
            }
            .frame(width: 300, height: 60)
            .glassBackgroundEffect()
        })
    }
}

In a production app we might want to create an enum with all possible states. What we do with each state would depend on our scene type and app requirements. For example, a window or volume could show errors and metadata in ornaments. An immersive space could render attachments with the same data.

If we need to load an entire Reality Composer Pro project we could try this idea mentioned on the Developer Forums. Keep in mind that this is limited to standard components. Custom components need to be complied so they can’t be loaded as an assets.

Support our work so we can continue to bring you new examples and articles.

Download the Xcode project with this and many more examples from Step Into Vision.
Some examples are provided as standalone Xcode projects. You can find those here.

Questions or feedback?