Search Unity

  1. We are migrating the Unity Forums to Unity Discussions. On July 12, the Unity Forums will become read-only. On July 15, Unity Discussions will become read-only until July 18, when the new design and the migrated forum contents will go live. Read our full announcement for more information and let us know if you have any questions.

Bug [OpenXR] Interaction Profiles not present when building in batch mode

Discussion in 'VR' started by hschulte, Sep 17, 2021.

  1. hschulte

    hschulte

    Joined:
    Oct 2, 2018
    Posts:
    13
    Unity: 2021.1.16f1
    XR Plugin Management: 4.0.7
    OpenXR Plugin: 1.2.8
    Hardware: Oculus Quest Link, HP Reverb 2 and HTC Vive.

    I'm encountering a strange problem, where controller devices are not recognized in builds created by our CI pipeline. It works fine in Editor and even when creating a build from the Editor GUI. Trying to narrow down where this bug came from, I skimmed through the CI job logs and found the following:

    Code (CSharp):
    1.  
    2. ProgressiveSceneManager::Cancel()
    3. building x86_64 windows player!
    4. At least one interaction profile must be added.  Please select which controllers you will be testing against in the Features menu.
    5. UnityEngine.StackTraceUtility:ExtractStackTrace ()
    6. UnityEngine.DebugLogHandler:LogFormat (UnityEngine.LogType,UnityEngine.Object,string,object[])
    7. UnityEngine.Logger:Log (UnityEngine.LogType,object)
    8. UnityEngine.Debug:LogWarning (object)
    9. UnityEditor.XR.OpenXR.OpenXRProjectValidation:LogBuildValidationIssues (UnityEditor.BuildTargetGroup) (at Library/PackageCache/com.unity.xr.openxr@1.2.8/Runtime/OpenXRProjectValidation.cs:209)
    10. UnityEditor.XR.OpenXR.OpenXRProjectValidationBuildStep:OnPreprocessBuild (UnityEditor.Build.Reporting.BuildReport) (at Library/PackageCache/com.unity.xr.openxr@1.2.8/Editor/OpenXRProjectValidationWindow.cs:295)
    11. UnityEditor.Build.BuildPipelineInterfaces/<>c__DisplayClass15_0:<OnBuildPreProcess>b__1 (UnityEditor.Build.IPreprocessBuildWithReport)
    12. UnityEditor.Build.BuildPipelineInterfaces:InvokeCallbackInterfacesPair<UnityEditor.Build.IPreprocessBuild, UnityEditor.Build.IPreprocessBuildWithReport> (System.Collections.Generic.List`1<UnityEditor.Build.IPreprocessBuild>,System.Action`1<UnityEditor.Build.IPreprocessBuild>,System.Collections.Generic.List`1<UnityEditor.Build.IPreprocessBuildWithReport>,System.Action`1<UnityEditor.Build.IPreprocessBuildWithReport>,bool)
    13. UnityEditor.Build.BuildPipelineInterfaces:OnBuildPreProcess (UnityEditor.Build.Reporting.BuildReport)
    14.  
    15. (Filename: Library/PackageCache/com.unity.xr.openxr@1.2.8/Runtime/OpenXRProjectValidation.cs Line: 209)
    In the editor window it looks like this:
    upload_2021-9-17_13-25-21.png

    I presume that there is something wrong with the deserialization of the openxr asset when using batch mode. This is causing no interaction profiles to be active in the build and therefore my controller devices do not show up.

    This is the call we use to create the build in batch mode:

    Code (CSharp):
    1. C:\MyProject\Unity\2021.1.16f1\Editor\Unity.exe
    2. -rebuildlibrary
    3. -projectPath
    4. C:\Gitlab-Runner\builds\MyProject
    5. -buildWindows64Player
    6. C:\Gitlab-Runner\builds\MyProject\Build\MyProject.exe
    7. -batchmode
    8. -quit
    9. -logFile
    10. C:\Gitlab-Runner\builds\MyProject\logFile.txt
    Edit: I could also reproduce this locally when building from the CLI
    Edit2: Also happens without
    -rebuildlibrary
     
    Last edited: Sep 17, 2021
  2. hschulte

    hschulte

    Joined:
    Oct 2, 2018
    Posts:
    13
    Dark-Table likes this.
  3. Dark-Table

    Dark-Table

    Joined:
    Nov 25, 2008
    Posts:
    315
    That bug report shows the behavior wasn't present in 4.0.5 and is present in 4.0.6. I think this is where the issue was introduced:
    Screen Shot 2021-09-19 at 8.05.34 AM.png
    Looks like it was technically a bug, but desired behavior, that BeginPackageInitialization wasn't executing when using batch mode.

    As a workaround, you might be able to use OnPreprocessBuild to re-enable the desired interaction profiles before the build starts?
    https://docs.unity3d.com/ScriptReference/Build.IPreprocessBuildWithReport.OnPreprocessBuild.html
     
  4. hschulte

    hschulte

    Joined:
    Oct 2, 2018
    Posts:
    13
    Yes, it looks like this is where the problem was introduced.

    I already tried do a workaround in the PreprocessBuild step. However the interaction profiles in
    OpenXRSettings
    are all read-only and I couldn't figure out how to activate them manually.

    Edit: Going back to 4.0.5 seems to be the best workaround so far.
     
    Last edited: Sep 20, 2021
  5. Dark-Table

    Dark-Table

    Joined:
    Nov 25, 2008
    Posts:
    315
    I haven't tested this with the batchmode bug, but this is able to repopulate the Interaction Profiles list of the OpenXR settings if it's been emptied.

    Code (CSharp):
    1. using UnityEditor;
    2. using UnityEngine.XR.OpenXR;
    3. using System.Linq;
    4. using UnityEngine.XR.OpenXR.Features;
    5. public class ModifyOpenXRSettings : EditorWindow
    6. {
    7.     private static readonly string[] enabledFeatures = new []{"HTCViveControllerProfile", "MicrosoftMotionControllerProfile", "OculusTouchControllerProfile", "ValveIndexControllerProfile"};
    8.  
    9.     [MenuItem("Tools/Test Modification")]
    10.     private static void EnableOpenXRInteractionFeatures() {
    11.         var settings = OpenXRSettings.GetSettingsForBuildTargetGroup(BuildTargetGroup.Standalone);
    12.         var features = settings.GetFeatures<OpenXRInteractionFeature>();
    13.  
    14.         foreach (var feature in features) {
    15.             var settingName = feature.GetType().Name;
    16.  
    17.             feature.enabled = enabledFeatures.Contains(settingName);
    18.         }
    19.  
    20.         EditorUtility.SetDirty(settings);
    21.     }
    22. }
    23.  
     
    hschulte likes this.
  6. hschulte

    hschulte

    Joined:
    Oct 2, 2018
    Posts:
    13
    I just tried this but unfortunately it didn't work.

    Code (CSharp):
    1. public class FixOpenXRInteractionProfiles : IPreprocessBuildWithReport
    2. {
    3.     private static readonly string[] enabledFeatures =
    4.     {
    5.         "HTCViveControllerProfile",
    6.         "MicrosoftMotionControllerProfile",
    7.         "OculusTouchControllerProfile",
    8.         "ValveIndexControllerProfile"
    9.     };
    10.  
    11.     public int callbackOrder => -1;
    12.  
    13.     public void OnPreprocessBuild(BuildReport report)
    14.     {
    15.         var settings = OpenXRSettings.GetSettingsForBuildTargetGroup(BuildTargetGroup.Standalone);
    16.      
    17.         if (settings == null)
    18.         {
    19.             Debug.Log($"No OpenXR settings found.");
    20.             return;
    21.         }
    22.  
    23.         var features = settings.GetFeatures<OpenXRInteractionFeature>();
    24.  
    25.         if (settings.featureCount == 0)
    26.         {
    27.             Debug.Log($"No interaction profiles defined. Working around Unity bugs once again ...");
    28.  
    29.             foreach (var feature in features) {
    30.                 var settingName = feature.GetType().Name;
    31.                 feature.enabled = enabledFeatures.Contains(settingName);
    32.             }
    33.             EditorUtility.SetDirty(settings);
    34.          
    35.         }
    36.         else
    37.         {
    38.             Debug.Log($"{features.Length} Interaction profiles found. No action required. " +
    39.                       $"Features: {string.Join(", ", features.Where(f => f.enabled).Select(f => f.name))}");
    40.         }
    41.     }
    42. }
    43.  
    Output was:

    Code (CSharp):
    1. No interaction profiles defined. Working around Unity bugs once again ...
    2. At least one interaction profile must be added.  Please select which controllers you will be testing against in the Features menu.
    Edit: I also tried to call
    XRPackageInitializationBootstrap.BeginPackageInitialization()
    by reflection but that does not work either.
     
    Last edited: Sep 21, 2021
  7. Dark-Table

    Dark-Table

    Joined:
    Nov 25, 2008
    Posts:
    315
    Oooph. This is quite vexing. Thanks for trying it.
     
  8. the_real_apoxol

    the_real_apoxol

    Unity Technologies

    Joined:
    Dec 18, 2020
    Posts:
    467
    We have a fix for this issue in XR.SDK.MANAGEMENT that is making its way through the testing / release cycle. The Issue is that `BeginPackageInitialization` is called too early, before the asset database is loaded and is wiping out the openxr package settings. We dont have an ETA yet for release of this fix.

    Our testing has showed this only happens when the Library folder is missing though. So there may be a workaround that you could try while you wait for the fix if you are blocked, but note that I have not personally tried this. This assumes that your Library folder is missing and that is why you are running into this issue.

    1) Make a copy of the OpenXR Package settings file
    2) Run unity in batch mode with some empty executeMethod function (this will build the library folder but also clobber your package settings)
    3) Copy the old package settings over the newly clobbered one after unity exits
    4) Run your actual batchmode operation
     
    Dark-Table and hschulte like this.
  9. hschulte

    hschulte

    Joined:
    Oct 2, 2018
    Posts:
    13
    Thank you for clearing this up. For now, I will stick to 4.0.5 to avoid this bug.
     
    Deleted User likes this.