<!--
{
  "availability" : [
    "iOS: -",
    "iPadOS: -",
    "visionOS: 26.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "RealityKit",
  "identifier" : "/documentation/RealityKit/ViewAttachmentComponent/init(rootView:)",
  "metadataVersion" : "0.1.0",
  "role" : "Initializer",
  "symbol" : {
    "kind" : "Initializer",
    "modules" : [
      "RealityKit",
      "SwiftUI"
    ],
    "preciseIdentifier" : "s:19_RealityKit_SwiftUI23ViewAttachmentComponentV04rootE0ACx_tc0cD00E0Rzlufc"
  },
  "title" : "init(rootView:)"
}
-->

# init(rootView:)

A RealityKit component that manages a SwiftUI view hierarchy.

```
init<Content>(rootView: Content) where Content : View
```

## Discussion

Create a `ViewAttachmentComponent` component when you want to integrate SwiftUI
views into a RealityKit entity hierarchy. At creation time, specify the SwiftUI
view you want to use as the root view for this component; you can
change that view later by creating a new component with a new root view
and replacing the old component with the new one.
Use `ViewAttachmentComponent` like you would any other component, by
assigning it on an entity and adding that entity to your scene using a
[`RealityView`](/documentation/RealityKit/RealityView).

---

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)