Search Unity

Oculus, AR and Holelens in the same Unity Project

Discussion in 'AR/VR (XR) Discussion' started by FdenUijl, Nov 17, 2021.

  1. FdenUijl

    FdenUijl

    Joined:
    Sep 5, 2019
    Posts:
    29
    Hi everyone,

    We have a project that makes different applications for different platforms.
    - AR application
    - Hololens application
    - Oculus application

    And we want to make use of Unity Cloud Build to speed up the building process, this means switching between the different platforms by script.

    We added PLATFORM_OCULUS constraint to the all Oculus Integration SDK "Assembly Definition Assets", and to all scripts that depends on this.

    upload_2021-11-17_16-3-5.png

    Everythings works! That is if I delete the Oculus Integration SDK directory by hand and restart Unity.

    We are running this script before the build (IPreprocessBuildWithReport):

    Code (CSharp):
    1.  
    2.         public void ExludeFolders()
    3.         {
    4.             foreach(var dirPath in configuration.DirectoriesToExlude)
    5.             {
    6. #if UNITY_CLOUD_BUILD
    7.                 var isRemoved = AssetDatabase.DeleteAsset(dirPath);
    8.  
    9.                 if(isRemoved)
    10.                 {
    11.                     Debug.Log("Removed: " + dirPath);
    12.                 }
    13.                 else
    14.                 {
    15.                     throw new BuildFailedException("NOT Removed: " + dirPath);
    16.                 }
    17. #else
    18.                 if(!dirPath.Contains("~"))
    19.                 {
    20.                
    21.                     var dirName = dirPath.Split('/').Last();
    22.                     var error = AssetDatabase.RenameAsset(dirPath, dirName + "~");
    23.  
    24.                     if(!string.IsNullOrEmpty(error))
    25.                     {
    26.                         throw new BuildFailedException("Unable to exclude folder: "+dirName+"! Restarting helps.");
    27.                     }
    28.  
    29.                     Debug.Log("Hide folder: " + dirPath);  
    30.                 }
    31. #endif
    32.             }
    33.        
    34.             AssetDatabase.Refresh();
    35.         }
    This works:
    - Remove Oculus directory by hand in the editor
    - Re-open Unity
    - Build APK + obb
    - build no errors
    - Everything works!

    This doesn't:
    - Run the build with pre-build script on Editor or Unity Cloud Build (both same result)
    - Build APK + obb
    - build no errors
    - APK crash on start-up! (also iOS)

    The build crashes at start-up at this line, when the folder is deleted by script:
    Code (CSharp):
    1. var prefabResource = Resources.Load(resourcePath);
    (The crash isn't send to Unity Cloud Build, its a hard crash)

    This happens (I think) because of native plugins, they are loaded into memory and makes my build crash on start-up. It makes my .obb corupted and crashes when I do a Resources.Load call.

    (I have reproduced this multiple times)

    So I have two question:
    1. Am I right that this is because the native plugins loaded into memery before I make a build? Or something else that is still in memory..
    2. How can I stop Oculus for loading these native plug-ins/stuff before I run this on Unity Cloud Build? I want to exclude the Oculus directory when I add PLATFORM_OCULUS in the scripting define symbols.

     

    Attached Files:

    hippocoder likes this.
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,745
    One way is to use source control branches and remove the unwanted SDKs from particular branches, then merge fresh work into it. I use this for Android TV builds of my games, which I primarily build for non-TV targets.

    These guys might have more approaches that work well with the VR/XR/AR stuff:

    https://forum.unity.com/forums/ar-vr-xr-discussion.80/
     
  3. FdenUijl

    FdenUijl

    Joined:
    Sep 5, 2019
    Posts:
    29
    Thanks for your reply.

    I wanted to asked the ar/vr/ax community but I'm unable; "You have insufficient privileges to post here."

    I do look for a different approach, strange that I'm unable to exclude folders when building on Unity Cloud Build.
     
  4. FdenUijl

    FdenUijl

    Joined:
    Sep 5, 2019
    Posts:
    29
  5. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    This sounds like a huge problem to me - a bug Unity needs to deal with. Moved thread too so you should be able to post.

    This isn't something that should require workarounds, Unity's always been able to deploy to multiple (XR/MR) targets so please post a bug report case number if you have one.
     
  6. FdenUijl

    FdenUijl

    Joined:
    Sep 5, 2019
    Posts:
    29
    Can confirm that running a Pre-build shell script on Unity Cloud Build fixed my problem. For other people who have the same issue:

    UnityCloudBuildScript.sh
    Code (CSharp):
    1. #!/bin/bash
    2.  
    3. rm -r Assets/Oculus
    Should do the trick ;)

    Will report a bug later today.
     
    hippocoder likes this.
  7. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Brilliant thanks!