---
title: "init(contentsOf:withName:)"
framework: realitykit
role: symbol
role_heading: Initializer
path: "realitykit/entity/init(contentsof:withname:)"
---

# init(contentsOf:withName:)

Creates an entity by asynchronously loading it from a file URL.

## Declaration

```swift
@MainActor @preconcurrency convenience init(contentsOf url: URL, withName resourceName: String? = nil) async throws
```

## 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.

## Return Value

Return Value The root entity of the loaded file.

## Discussion

Discussion 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. Construct the URL using URLComponents or URL(string:) to preserve the fragment: var components = URLComponents() components.scheme = "file" components.path = "/path/to/MyContent.reality" components.fragment = "MyScene"

if let url = components.url {     let entity = try await Entity(contentsOf: url) } For more information on loading entities, see Loading entities from a file. See init(named:in:) for an example of optimally loading content.

## See Also

### Loading an entity from a file

- [Generating procedural textures](visionos/generating-procedural-textures-in-visionos.md)
- [Resource](realitykit/resource.md)
- [Loading entities from a file](realitykit/loading-entities-from-a-file.md)
- [Stored entities](realitykit/stored-entities.md)
- [Creating USD files for Apple devices](usd/creating-usd-files-for-apple-devices.md)
- [init(named:in:)](realitykit/entity/init(named:in:).md)
- [ReferenceComponent](realitykit/referencecomponent.md)
