ARKit Hand Tracking Basics
A simple RealityKit scene that uses HandTrackingProvider to update anchors on our hands.
This article providers the simplest explanation of hand tracking that I’ve see for visionOS. Let’s break down the concepts and learn how to build on these.
Our first task is to set a value for NSHandsTrackingUsageDescription in the project Plist.

<key>NSHandsTrackingUsageDescription</key>
<string>Hand tracking access is needed to explore the Hand tracking example code</string>We need to create an ARKit Session and a HandTrackingProvider in our SwiftUI view.
let arSession = ARKitSession()
let handTrackingProvider = HandTrackingProvider()We’re going to create a sphere for each finger, then anchor them to the finger tips. We’ll need somewhere to keep track of our entities.
let leftCollection = Entity()
let rightCollection = Entity()We only care about the finger tips. We can create an array to spawn our spheres. This array will also check for anchor updates. There are many other anchors available for hands.
let tipJoints: [HandSkeleton.JointName] = [
.thumbTip, .indexFingerTip, .middleFingerTip, .ringFingerTip, .littleFingerTip
]We import a scene from our RealityKitContent bundle, then get the entity to clone.
if let leftHandSphere = scene.findEntity(named: "StepSphereBlue") {
for jointName in tipJoints {
let sphere = leftHandSphere.clone(recursive: true)
sphere.name = jointName.description
leftCollection.addChild(sphere)
}
leftHandSphere.isEnabled = false
}The real work is done by the tasks. We can kick off the ARKit session with our provider.
.task { try! await arSession.run([handTrackingProvider]) }This provider will provide (haha) a continuous stream up updates, which we can listen for via for await. This task will fire only when the SwiftUI view is created. However, the loop will continue as long as the provider is active. When the provider has anchorUpdates, it will obtain the joints for the hand. It will then update the transform of our spheres to match the joints.
.task {
for await update in handTrackingProvider.anchorUpdates where update.anchor.chirality == .left {
let handAnchor = update.anchor
for jointName in tipJoints {
if let joint = handAnchor.handSkeleton?.joint(jointName),
let sphere = leftCollection.findEntity(named: jointName.description) {
let transform = handAnchor.originFromAnchorTransform
let jointTransform = joint.anchorFromJointTransform
sphere.setTransformMatrix(transform * jointTransform, relativeTo: nil)
}
}
}
}I broke this out to Left and Right hands so I could experiment with different ideas. For example, we could use handTrackingProvider.latestAnchors instead of handTrackingProvider.anchorUpdates.
In this version, we poll for updates instead of receiving them. I didn’t notice much of a difference in the results, so I’m going to stick with anchorUpdates.
// Alternate version using latestAnchors instead of anchorUpdates
.task {
while true {
let anchors = handTrackingProvider.latestAnchors
if let handAnchor = anchors.rightHand {
for jointName in tipJoints {
if let joint = handAnchor.handSkeleton?.joint(jointName),
let sphere = rightCollection.findEntity(named: jointName.description) {
let transform = handAnchor.originFromAnchorTransform
let jointTransform = joint.anchorFromJointTransform
sphere.setTransformMatrix(transform * jointTransform, relativeTo: nil)
}
}
}
try? await Task.sleep(for: .milliseconds(8)) // ~120fps
}
}Video Demo
Full example code:
struct Example017: View {
let arSession = ARKitSession()
let handTrackingProvider = HandTrackingProvider()
let leftCollection = Entity()
let rightCollection = Entity()
let tipJoints: [HandSkeleton.JointName] = [
.thumbTip, .indexFingerTip, .middleFingerTip, .ringFingerTip, .littleFingerTip
]
var body: some View {
RealityView { content in
content.add(leftCollection)
content.add(rightCollection)
if let scene = try? await Entity(named: "HandTrackingLabs", in: realityKitContentBundle) {
content.add(scene)
if let leftHandSphere = scene.findEntity(named: "StepSphereBlue") {
// Create clones of the left hand sphere for each joint
for jointName in tipJoints {
let sphere = leftHandSphere.clone(recursive: true)
sphere.name = jointName.description
leftCollection.addChild(sphere)
}
leftHandSphere.isEnabled = false
}
if let rightHandSphere = scene.findEntity(named: "StepSphereGreen") {
// Create clones of the right hand sphere for each joint
for jointName in tipJoints {
let sphere = rightHandSphere.clone(recursive: true)
sphere.name = jointName.description
rightCollection.addChild(sphere)
}
rightHandSphere.isEnabled = false
}
}
}
.persistentSystemOverlays(.hidden)
.task { try! await arSession.run([handTrackingProvider]) }
// Left Hand: Receive updates from the provider and process them over time
.task {
for await update in handTrackingProvider.anchorUpdates where update.anchor.chirality == .left {
let handAnchor = update.anchor
for jointName in tipJoints {
if let joint = handAnchor.handSkeleton?.joint(jointName),
let sphere = leftCollection.findEntity(named: jointName.description) {
let transform = handAnchor.originFromAnchorTransform
let jointTransform = joint.anchorFromJointTransform
sphere.setTransformMatrix(transform * jointTransform, relativeTo: nil)
}
}
}
}
// Right Hand: Receive updates from the provider and process them over time
.task {
for await update in handTrackingProvider.anchorUpdates where update.anchor.chirality == .right {
let handAnchor = update.anchor
for jointName in tipJoints {
if let joint = handAnchor.handSkeleton?.joint(jointName),
let sphere = rightCollection.findEntity(named: jointName.description) {
let transform = handAnchor.originFromAnchorTransform
let jointTransform = joint.anchorFromJointTransform
sphere.setTransformMatrix(transform * jointTransform, relativeTo: nil)
}
}
}
}
// Alternate version using latestAnchors instead of anchorUpdates
// .task {
// while true {
// let anchors = handTrackingProvider.latestAnchors
// if let handAnchor = anchors.rightHand {
// for jointName in tipJoints {
// if let joint = handAnchor.handSkeleton?.joint(jointName),
// let sphere = rightCollection.findEntity(named: jointName.description) {
// let transform = handAnchor.originFromAnchorTransform
// let jointTransform = joint.anchorFromJointTransform
// sphere.setTransformMatrix(transform * jointTransform, relativeTo: nil)
// }
// }
// }
// try? await Task.sleep(for: .milliseconds(8)) // ~120fps
// }
// }
}
}Support our work so we can continue to bring you new examples and articles.

Follow Step Into Vision