Contents

load(contentsOf:withName:)

Returns an entity by synchronously loading it from a file URL.

Declaration

@MainActor @preconcurrency static func load(contentsOf url: URL, withName resourceName: String? = nil) throws -> Entity

Parameters

  • url:

    A file URL representing the file to load. For Reality files, append a URL fragment to specify a scene name — for example, my.reality#MyScene.

  • resourceName:

    A unique name the method assigns to the resource it loads, for use in network synchronization.

Mentioned in

Return Value

The root entity in the loaded file.

Discussion

Loading an Entity with this method blocks the main actor because it’s synchronous, so only call it from a command-line application. The method can stall a regular app, which makes it visibly hitch, and the system terminates an app if its UI becomes unresponsive. See init(named:in:) for an example that demonstrates how to safely load content.

RealityKit supports loading entities from USD (.usd, .usda, .usdc, .usdz) and Reality (.reality) files. For Reality files that contain multiple scenes, specify which scene to load by appending a URL fragment with the scene name — for example, my.reality#MyScene.

For more information on loading entities, see Loading entities from a file.

See Also

Loading an entity hierarchy