Search Unity

Bug xr plugin manager enables arkit but does not build with it

Discussion in 'Editor & General Support' started by keil_unity, Apr 28, 2022.

  1. keil_unity

    keil_unity

    Joined:
    Mar 2, 2021
    Posts:
    28
    I am currently enabled ARKit through my build pipeline I can confirm the setting in xr-plugin-management->Ios->Arkit is enabled

    But when I build my application for IOS ARKIT is not included in Unity root in the xcode UnityFramework.

    Below is the code I am using
    Code (CSharp):
    1.     [MenuItem("Tools/EnableARKit")]
    2.     private static void enableArkit()
    3.     {
    4.         var metadata = XRPackageMetadataStore.GetMetadataForPackage("com.unity.xr.arkit");
    5.         Debug.Log(metadata);
    6.         var assets = AssetDatabase.FindAssets($"t:{metadata.settingsType}");
    7.         var assetPath = AssetDatabase.GUIDToAssetPath(assets[0]);
    8.  
    9.         // Settings access is type specific. You will need information from your plug-in documentation
    10.         // to know how to get at specific instances and properties.
    11.  
    12.         // You must know the type of the settings you are accessing.
    13.         var directInstance  = AssetDatabase.LoadAssetAtPath(assetPath, typeof(ARKitSettings));
    14.  
    15.         // You must know the access method for getting build target specific settings data.
    16.         var buildTargetSettings = XRGeneralSettingsPerBuildTarget.XRGeneralSettingsForBuildTarget(BuildTargetGroup.iOS);
    17.  
    18.         var fooLoader = ScriptableObject.CreateInstance<ARKitLoader>();
    19.         fooLoader.name = "UnityEngine.XR.ARKit.ARKitLoader";
    20.         // Adding new loaders
    21.         // Append the new FooLoader
    22.         if (!buildTargetSettings.Manager.TryAddLoader(fooLoader))
    23.             Debug.Log("Adding new Foo Loader failed! Refer to the documentation for additional information!");
    24.        
    25.         // Modifying the loader list order
    26.         var readonlyCurrentLoaders = buildTargetSettings.Manager.activeLoaders;
    27.  
    28.         // Copy the returned read only list
    29.         var currentLoaders = new List<XRLoader>(readonlyCurrentLoaders);
    30.         var pluginsSettings = buildTargetSettings.AssignedSettings;
    31.         foreach (var loader in currentLoaders)
    32.         {
    33.             var didAssign = XRPackageMetadataStore.AssignLoader(pluginsSettings, loader.name, BuildTargetGroup.iOS);
    34.             if (!didAssign)
    35.             {
    36.                 Debug.Log("LOADER failed to assign: " + loader);
    37.             }
    38.             else
    39.             {
    40.                 Debug.Log("Assign successful of: " + loader);
    41.             }
    42.         }
    43.        
    44.         // Reverse the list
    45.         currentLoaders.Reverse();
    46.  
    47.         if (!buildTargetSettings.Manager.TrySetLoaders(currentLoaders))
    48.             Debug.Log("Failed to set the reordered loader list! Refer to the documentation for additional information!");
    49.  
    50.        // Mark instance dirty and save any changes.
    51.         EditorUtility.SetDirty(directInstance);
    52.         AssetDatabase.SaveAssets();
    53.     }
    54.