How to use ARCoaching with AR Foundation?

I use AR Foundation and I want to display a ARCoachingOverlay (which is a feature of the ARKit). According to the manual you have to use SubsystemManager. I can create a XRSessionSubsystem and cast it to a ARKitSessionSubsystem. But when I try to use the returned ARKitSessionSubsystem then its properties are not exposed and I can only access the XRSessionSubsystem properties. How can I set for example the coachingActivatesAutomatically property?

(Unity provides an example how to use coaching but the method used in the example is depricated.)

I use Unity 2019.3.0b7 and I have the following packages installed:

  • ARFoundation 2.1.4
  • ARKit XR Plugin 2.1.2
  • ARSubsystems 2.1.1

I create the ARKitSessionSubsystem as follows.

ARKitSessionSubsystem CreateSubsystem()
{
    var descriptors = new List<XRSessionSubsystemDescriptor>();
    SubsystemManager.GetSubsystemDescriptors(descriptors);

    foreach (var descriptor in descriptors)
    {
        if (descriptor is XRSessionSubsystemDescriptor)
        {
                return (ARKitSessionSubsystem)descriptor.Create();
        }
    }
    return null;
}

documentaion of the ARKitSessionSubsystem class.
https://docs.unity3d.com/Packages/com.unity.xr.arkit@3.0/api/UnityEngine.XR.ARKit.ARKitSessionSubsystem.html

I solved the problem by updating the ARFoundation, ARKit XR and ARSubsystems packages to preview version 3.0. Then you can access the ARKitSessionSubsystem.

if (GetComponent<ARSession>().subsystem is ARKitSessionSubsystem sessionSubsystem)
            {
                return sessionSubsystem.coachingGoal;
            }
            else
            {
                return (ARCoachingGoal)m_Goal;
            }
1 Like