ManipulationComponent create parent/child crash

Hello,

If you add a ManipulationComponent to a RealityKit entity and then continue to add instructions, sooner or later you will encounter a crash with the following error message:

Attempting to move entity “%s” (%p) under “%s” (%p), but the new parent entity is currently being removed. Changing the parent/child entities of an entity in an event handler while that entity is already being reassigned is not supported. CoreSimulator 1048 – Device: Apple Vision Pro 4K (B87DD32A-E862-4791-8B71-92E50CE6EC06) – Runtime: visionOS 26.0 (23M336) – Device Type: Apple Vision Pro

The problem occurs precisely with this code:

ManipulationComponent.configureEntity(object)

I adapted Apple's ObjectPlacementExample and made the changes available via GitHub.

The desired behavior is that I add entities to ManipulationComponent and then Realitiykit runs stably and does not crash randomly.

GitHub Repo

Thanks

Andre

Answered by bitsmaker in 862936022

So I found my problem. It was a little tricky. I can't double add the ManipulationComponent to an Entity.

Then I comment the var mc = ManipulationComponent() out it works stable.

ManipulationComponent.configureEntity(entity)
            // var mc = ManipulationComponent()
            if var mc = entity.components[ManipulationComponent.self] {
                mc.releaseBehavior = .stay
                mc.dynamics.primaryRotationBehavior = .none
                entity.components.set(mc)
                
            }

I created a feedback ticket for it: FB20653552

I downloaded this and added a few objects. The only thing that stands out to me is you use of ManipulationComponent.configureEntity(). In my opinion, you shouldn't be using that here. This sample already does the heavy lifting of creating collision and input target components. You are essentially overwriting those.

Instead, try adding the component the "normal" way.

let object = objectToPlace.materialize()
let mc = ManipulationComponent()
object.components.set(mc)

A few other thoughts:

  • This doesn't add the ManipulationComponent when restoring the scene. It only adds it when you are anchoring a new item, but not when respawning them.
  • There may be some bugs or issues using ManipulationComponent along with ARKit.
  • Since this is based on an existing sample, check the rest of the project for things that may be causing issues.

I added around 30 items and never saw a crash or any errors.

Accepted Answer

So I found my problem. It was a little tricky. I can't double add the ManipulationComponent to an Entity.

Then I comment the var mc = ManipulationComponent() out it works stable.

ManipulationComponent.configureEntity(entity)
            // var mc = ManipulationComponent()
            if var mc = entity.components[ManipulationComponent.self] {
                mc.releaseBehavior = .stay
                mc.dynamics.primaryRotationBehavior = .none
                entity.components.set(mc)
                
            }
ManipulationComponent create parent/child crash
 
 
Q