How can I properly "consolidate" a combined ModelEntity?

Context being VisionOS development, I was trying to do something like

let root = ModelEntity()

child1 = ModelEntity(...)
root.addChild(child1)

child2 = ModelEntity(...)
root.addChild(child2)

only to find that, despite seemingly being together, I can only pick by children entities when I apply a DragGesture in VisionOS. Any idea what's going on?

Hi @allenfrostline

I assume that you are using the generateCollisionShapes method for your root entity. Please ensure that you set the recursive parameter to true so that collision shapes will be created for the child entities too.

Here is an example code snippet for a view.

struct ContentView: View {
  @State var parentEntity: Entity = Entity()

    var body: some View {
        VStack {
          RealityView { content in

            parentEntity = ModelEntity(
              mesh: .generateBox(size: 0.1),
              materials: [SimpleMaterial(color: .blue, isMetallic: false)])

            let childEntity = ModelEntity(
              mesh: .generateBox(size: 0.05),
              materials: [SimpleMaterial(color: .yellow, isMetallic: false)])

            childEntity.transform = Transform(translation: [0, 0.1, 0])

            parentEntity.addChild(childEntity)

            parentEntity.components.set(InputTargetComponent())
            parentEntity.generateCollisionShapes(recursive: true)
 
            content.add(parentEntity)
          }
          .gesture(
              DragGesture()
                .targetedToEntity(parentEntity)
                .onChanged { value in
                  parentEntity.position = value.convert(value.location3D, from: .local, to: parentEntity.parent!)
                }
            )
        }
        .padding()
    }
}

The above code creates a parent entity and positions a child entity right above it. Notice that in the generateCollisionShapes method call we set the recursive flag to true to ensure that you will be able to apply gestures to the child entity too. We then add a DragGesture targeted to the parentEntity which should enable you to drag using either the parent or child entity.

How can I properly "consolidate" a combined ModelEntity?
 
 
Q