Unable to create PhysicsJoint using Entity's Geometric Pin

Hello,

I'm trying to attach one entity to another entity via the new PhysicsFixedJoint. I have a usdz that contains a skeletal pose which expose the joints as pins as desired. However the when I access the pin, it is returning a GeometricPin, instead of an EntityGeometricPin as you would expect. I can't use the returned GeometricPin to create the joint.

Am I missing something? Shouldn't access the Entity's pins object return EntityGeometricPins instead of GeometricPin?

Here is the code sample:

var body: some View {
        RealityView { content in
            if let scene = try? await Entity(named: "Scene", in: untitledBundle) {
                content.add(scene)
                
                let attack = try! Entity.load(named: "Attack01_SingleSword")
                let anchor = scene.findEntity(named: "Root")
                anchor?.addChild(attack)
                
                let sword = try! Entity.load(named: "OHS08_Sword")
                anchor?.addChild(sword)
                
                if let swordEntity = findModelComponentEntity(entity: sword) {
                    let swordPin = swordEntity.pins.set(
                        named: "test", position: SIMD3<Float>.zero
                    )
                    
                    if let attackEntity = findModelComponentEntity(entity: attack) {
                        let attackPin = attackEntity.pins["root/pelvis/spine_01/spine_02/spine_03/clavicle_r/upperarm_r/lowerarm_r/hand_r/weapon_r"]! // This is returning GeomtricPin instead of the EntityGeometricPin that the "pins" object contains

                        let joint = PhysicsFixedJoint(
                            pin0: swordPin,
                            pin1: attackPin // This is a compile error since it is not an EntityGeometricPin type
                        )
                        try! joint.addToSimulation()
                    }
                }
            }
        }
    }
Answered by jirikripac in 793161022

You can only use physics joints to connect physics entities, i.e. entities with PhysicsBodyComponent. To make one entity follow another entity even if they are not both physics entities, use:

swordEntity.align(swordPin, to: attackPin)

You need to make this call on every update because it doesn't create a joint maintained by physics, it just translates and rotates swordEntity to make the pins aligned.

Regarding the attackPin, simply create it from the entity and the name of an existing joint/pin:

let jointName = "root/pelvis/spine_01/..."
let attackPin = EntityGeometricPin(entity: attackEntity, pinName: jointName)                   
Accepted Answer

You can only use physics joints to connect physics entities, i.e. entities with PhysicsBodyComponent. To make one entity follow another entity even if they are not both physics entities, use:

swordEntity.align(swordPin, to: attackPin)

You need to make this call on every update because it doesn't create a joint maintained by physics, it just translates and rotates swordEntity to make the pins aligned.

Regarding the attackPin, simply create it from the entity and the name of an existing joint/pin:

let jointName = "root/pelvis/spine_01/..."
let attackPin = EntityGeometricPin(entity: attackEntity, pinName: jointName)                   

The model's pins are now empty starting with Xcode Beta 4+. I'm no longer able to access any of the joint pins, the count is always 0, even though my model has a skeleton

Anyone else run into this problem?

Unable to create PhysicsJoint using Entity's Geometric Pin
 
 
Q