<!--
{
  "availability" : [
    "iOS: 18.0.0 -",
    "iPadOS: 18.0.0 -",
    "macCatalyst: 18.0.0 -",
    "macOS: 15.0.0 -",
    "tvOS: 26.0.0 -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "RealityKit",
  "identifier" : "/documentation/RealityKit/Entity/init(contentsOf:withName:)",
  "metadataVersion" : "0.1.0",
  "role" : "Initializer",
  "symbol" : {
    "kind" : "Initializer",
    "modules" : [
      "RealityKit"
    ],
    "preciseIdentifier" : "s:17RealityFoundation6EntityC10contentsOf8withNameAC0B03URLV_SSSgtYaKcfc"
  },
  "title" : "init(contentsOf:withName:)"
}
-->

# init(contentsOf:withName:)

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

```
@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

The root entity of the loaded file.

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

```swift
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](/documentation/RealityKit/loading-entities-from-a-file).

See [`init(named:in:)`](/documentation/RealityKit/Entity/init(named:in:)) for an example of optimally loading content.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)