How to set tracking mode for a Hand Anchors

The default tracking mode .continuous is very accurate but it can lag slightly behind. We can also use .predicted, which can feel much faster but it has a tendency to overshoot during very fast motions.

We can specify tracking mode by providing AnchoringComponent.TrackingMode to an AnchorEntity

AnchorEntity(.hand(.left, location: .joint(for: .thumbTip)),trackingMode: .continuous)
AnchorEntity(.hand(.right, location: .joint(for: .thumbTip)),trackingMode: .predicted)

In this example, we use .continuous mode for the left hand and .predicted for the right. It may be hard to see the difference in the video, so make sure you try both options yourself.

You can also set this when creating an Anchoring Component for an entity.

let entity = Entity()
var anchor = AnchoringComponent(
              .hand(.right, location: .joint(for: joint)),
              trackingMode: .continuous)
entity.components.set(anchor)

Full example code

struct Example022: View {
    var body: some View {
        RealityView { content in

            if let scene = try? await Entity(named: "HandTrackingLabs", in: realityKitContentBundle) {
                content.add(scene)

                let leftHandMode = AnchoringComponent.TrackingMode.continuous

                if let leftHandSphere = scene.findEntity(named: "StepSphereBlue") {


                    let leftThumbTip = AnchorEntity(.hand(.left, location: .joint(for: .thumbTip)),
                                                    trackingMode: leftHandMode)
                    leftThumbTip.addChild(leftHandSphere.clone(recursive: true))
                    content.add(leftThumbTip)

                    let leftIndexFingerTip = AnchorEntity(.hand(.left, location: .joint(for: .indexFingerTip)),
                                                      trackingMode: leftHandMode)
                    leftIndexFingerTip.addChild(leftHandSphere.clone(recursive: true))
                    content.add(leftIndexFingerTip)

                    let leftMiddleFingerTip = AnchorEntity(.hand(.left, location: .joint(for: .middleFingerTip)),
                                                           trackingMode: leftHandMode)
                    leftMiddleFingerTip.addChild(leftHandSphere.clone(recursive: true))
                    content.add(leftMiddleFingerTip)

                    let leftRingFingerTip = AnchorEntity(.hand(.left, location: .joint(for: .ringFingerTip)),
                                                         trackingMode: leftHandMode)
                    leftRingFingerTip.addChild(leftHandSphere.clone(recursive: true))
                    content.add(leftRingFingerTip)

                    let leftLittleFingerTip = AnchorEntity(.hand(.left, location: .joint(for: .littleFingerTip)),
                                                          trackingMode: leftHandMode)
                    leftLittleFingerTip.addChild(leftHandSphere.clone(recursive: true))
                    content.add(leftLittleFingerTip)

                }

                if let rightHandSphere = scene.findEntity(named: "StepSphereGreen") {

                    let rightHandMode = AnchoringComponent.TrackingMode.predicted

                    let rightThumbTip = AnchorEntity(.hand(.right, location: .joint(for: .thumbTip)),
                                                     trackingMode: rightHandMode)
                    rightThumbTip.addChild(rightHandSphere.clone(recursive: true))
                    content.add(rightThumbTip)

                    let rightIndexFingerTip = AnchorEntity(.hand(.right, location: .joint(for: .indexFingerTip)),
                                                           trackingMode: rightHandMode)
                    rightIndexFingerTip.addChild(rightHandSphere.clone(recursive: true))
                    content.add(rightIndexFingerTip)

                    let rightMiddleFingerTip = AnchorEntity(.hand(.right, location: .joint(for: .middleFingerTip)),
                                                            trackingMode: rightHandMode)
                    rightMiddleFingerTip.addChild(rightHandSphere.clone(recursive: true))
                    content.add(rightMiddleFingerTip)

                    let rightRingFingerTip = AnchorEntity(.hand(.right, location: .joint(for: .ringFingerTip)),
                                                          trackingMode: rightHandMode)
                    rightRingFingerTip.addChild(rightHandSphere.clone(recursive: true))
                    content.add(rightRingFingerTip)

                    let rightLittleFingerTip = AnchorEntity(.hand(.right, location: .joint(for: .littleFingerTip)),
                                                            trackingMode: rightHandMode)
                    rightLittleFingerTip.addChild(rightHandSphere.clone(recursive: true))
                    content.add(rightLittleFingerTip)
                }

            }
        }
        .persistentSystemOverlays(.hidden)
    }
}

Support our work so we can continue to bring you new examples and articles.

Questions or feedback?