ARCoachingOverlay in RealityKit?

Is there any sample code or pointers for using ARCoachingOverlay in RealityKit? The SwiftStrikeTT sample uses it but, although it builds, crashes the splash screen in Beta3 (iPad).


Any pointers appreciated!

Accepted Reply

Here is a basic example to set up the ARCoachingOverlay on top of an ARView:


let coachingOverlay = ARCoachingOverlayView(frame: arView.frame)
coachingOverlay.translatesAutoresizingMaskIntoConstraints = false
// Add overlay to the view hierarchy
arView.addSubview(coachingOverlay)
// Set Auto Layout constraints
coachingOverlay.topAnchor.constraint(equalTo: arView.topAnchor).isActive = true
coachingOverlay.leadingAnchor.constraint(equalTo: arView.leadingAnchor).isActive = true
coachingOverlay.trailingAnchor.constraint(equalTo: arView.trailingAnchor).isActive = true
coachingOverlay.bottomAnchor.constraint(equalTo: arView.bottomAnchor).isActive = true
// Specify a goal for the coaching overlay, in this case, the goal is to establish world tracking
coachingOverlay.goal = .tracking
// Tell the coaching overlay which ARSession it should be monitoring
coachingOverlay.session = arView.session


There is also an ARCoachingOverlayViewDelegate, which allows you to take action when certain coaching overlay events occur (for example, when it activates or deactivates).

Replies

Here is a basic example to set up the ARCoachingOverlay on top of an ARView:


let coachingOverlay = ARCoachingOverlayView(frame: arView.frame)
coachingOverlay.translatesAutoresizingMaskIntoConstraints = false
// Add overlay to the view hierarchy
arView.addSubview(coachingOverlay)
// Set Auto Layout constraints
coachingOverlay.topAnchor.constraint(equalTo: arView.topAnchor).isActive = true
coachingOverlay.leadingAnchor.constraint(equalTo: arView.leadingAnchor).isActive = true
coachingOverlay.trailingAnchor.constraint(equalTo: arView.trailingAnchor).isActive = true
coachingOverlay.bottomAnchor.constraint(equalTo: arView.bottomAnchor).isActive = true
// Specify a goal for the coaching overlay, in this case, the goal is to establish world tracking
coachingOverlay.goal = .tracking
// Tell the coaching overlay which ARSession it should be monitoring
coachingOverlay.session = arView.session


There is also an ARCoachingOverlayViewDelegate, which allows you to take action when certain coaching overlay events occur (for example, when it activates or deactivates).

For anyone looking for more information about ARCoaching, this article shows how to use it:


https://medium.com/@maxxfrazer/realitykit-arcoachingoverlayview-80159d140c