Skip to content

Instantly share code, notes, and snippets.

@durul
Last active October 25, 2025 18:21
Show Gist options
  • Select an option

  • Save durul/2ea9954527677d917e068fd0fb28876f to your computer and use it in GitHub Desktop.

Select an option

Save durul/2ea9954527677d917e068fd0fb28876f to your computer and use it in GitHub Desktop.
@MainActor
func placeInRealityView(modelURL: URL, into content: RealityViewContent, under parent: Entity?) async throws {
let entity = try await ModelEntity(contentsOf: modelURL)
var mc = ManipulationComponent()
ManipulationComponent.configureEntity(entity, collisionShapes: nil)
entity.components.set(mc)
let anchor = AnchorEntity(world: .zero)
content.add(anchor)
anchor.addChild(entity)
Task { @MainActor in
await Task.yield()
if let parent {
let hadMC = entity.components.has(ManipulationComponent.self)
if hadMC { entity.components.remove(ManipulationComponent.self) }
parent.addChild(entity, preservingWorldTransform: true)
if hadMC {
ManipulationComponent.configureEntity(entity, collisionShapes: nil)
entity.components.set(mc)
}
}
}
}
@bitsmakerde
Copy link

@durul thanks, but the ManipulationComponent has no member isEnable, did you extend the ManipulationComponent?

There you get the Scene, if I look by make Realityview I can get the scene.

@durul
Copy link
Author

durul commented Oct 25, 2025

@durul thanks, but the ManipulationComponent has no member isEnable, did you extend the ManipulationComponent?

There you get the Scene, if I look by make Realityview I can get the scene.

I've updated it. Sorry for sharing the wrong snippet; you probably couldn't compile it. I don't know your code or project, so it's hard to estimate your needs. Good Luck...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment