Search Unity

How to have different XR Plugin-Management Settings for server build

Discussion in 'AR/VR (XR) Discussion' started by Deleted User, Sep 2, 2020.

  1. Deleted User

    Deleted User

    Guest

    We are working on a project for a couple of years now and have migrated to the new XR system. Unfortunately, we only need XR on our client builds, a server build fails when we keep the standalone Oculus Plug-In Provider.
    So we need have that ticked on clients but not on the server.
    But how do you access that setting so it can be modified programmatically
     
    makaka-org likes this.
  2. joejo

    joejo

    Unity Technologies

    Joined:
    May 26, 2016
    Posts:
    958
  3. Deleted User

    Deleted User

    Guest

    @joejo thanks for that. One more, how do I toggle the "Initialize XR on Startup" option on lets say windows? I might want to test with Oculus Link in the editor or I might not. I would like to make that accessible from a Scene view GUI Toggle for quick switching.
     
  4. joejo

    joejo

    Unity Technologies

    Joined:
    May 26, 2016
    Posts:
    958
  5. Deleted User

    Deleted User

    Guest

    @joejo thx, I'll try that
     
  6. FromTheFuture

    FromTheFuture

    Joined:
    Jul 25, 2012
    Posts:
    57
    I'm reading the docs, but I'm confused about the reference to the XRManagerSettings instance. Is this a ScriptableObject that only needs to be created if you want to programmatically add a plugin in the editor? The docs for it are vaguely worded:
    For earlier versions of Unity, we have an editor script that would do this to enable Oculus, for example:
    Code (CSharp):
    1. PlayerSettings.virtualRealitySupported = true;
    2. UnityEditorInternal.VR.VREditor.SetVREnabledDevicesOnTargetGroup(BuildTargetGroup.Android, new string[] { "Oculus" });
    I'm unclear how to accomplish the same with XRPackageMetadataStore.AssignLoader. Or am I missing the mark completely?

    Thanks!
     
  7. FdenUijl

    FdenUijl

    Joined:
    Sep 5, 2019
    Posts:
    29
    Code (CSharp):
    1.         private void SetXRPlugins(string[] addPlugins, string[] removePlugins, UnityEditor.BuildTargetGroup buildTarget)
    2.         {
    3.             var xrSettings = XRGeneralSettingsPerBuildTarget.XRGeneralSettingsForBuildTarget(buildTarget);
    4.  
    5.             if(xrSettings == null)
    6.             {
    7.                 XRGeneralSettingsPerBuildTarget buildTargetSettings = null;
    8.                 EditorBuildSettings.TryGetConfigObject(XRGeneralSettings.k_SettingsKey, out buildTargetSettings);
    9.                 xrSettings = buildTargetSettings.SettingsForBuildTarget(BuildTargetGroup.Android);
    10.             }
    11.  
    12.             xrSettings.InitManagerOnStart = true;
    13.  
    14.             foreach(var addPlugin in addPlugins)
    15.             {
    16.                 if(!XRPackageMetadataStore.AssignLoader(xrSettings.Manager, addPlugin, buildTarget))
    17.                 {
    18.                     Debug.LogWarning("PLUGIN NOT ASSIGNED!: " + addPlugin);
    19.                 }
    20.             }
    21.  
    22.             foreach(var removePlugin in removePlugins)
    23.             {
    24.                 if(!XRPackageMetadataStore.RemoveLoader(xrSettings.Manager, removePlugin, buildTarget))
    25.                 {
    26.                     Debug.LogWarning("PLUGIN NOT REMOVED!: " + removePlugin);
    27.                 }
    28.             }
    29.  
    30.             EditorUtility.SetDirty(xrSettings);
    31.         }
    32. //Add Oculus and flip for AR
    33. var XRPluginsToAdd = new string[] { typeof(global::Unity.XR.Oculus.OculusLoader).FullName };
    34. var XRPluginsToRemove = new string[] { typeof(UnityEngine.XR.ARCore.ARCoreLoader).FullName };
    35.  
     
    Twil75 likes this.
  8. Twil75

    Twil75

    Joined:
    Aug 30, 2012
    Posts:
    22
    XRGeneralSettingsPerBuildTarget: Exactly what i want to set "Initialize XR on Startup" per platform (in my editor tools) !
     
  9. SaintOtis

    SaintOtis

    Joined:
    Aug 2, 2023
    Posts:
    2
    i have tried and i have been completely successful using these code snippets! I tried!