Oculus, AR and Holelens in the same Unity Project

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.

7665193--956944--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):

        public void ExludeFolders()
        {
            foreach(var dirPath in configuration.DirectoriesToExlude)
            {
#if UNITY_CLOUD_BUILD
                var isRemoved = AssetDatabase.DeleteAsset(dirPath);

                if(isRemoved)
                {
                    Debug.Log("Removed: " + dirPath);
                }
                else
                {
                    throw new BuildFailedException("NOT Removed: " + dirPath);
                }
#else
                if(!dirPath.Contains("~"))
                {
                
                    var dirName = dirPath.Split('/').Last();
                    var error = AssetDatabase.RenameAsset(dirPath, dirName + "~");

                    if(!string.IsNullOrEmpty(error))
                    {
                        throw new BuildFailedException("Unable to exclude folder: "+dirName+"! Restarting helps.");
                    }

                    Debug.Log("Hide folder: " + dirPath);  
                }
#endif
            }
        
            AssetDatabase.Refresh();
        }

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:

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.

7665193--956935--upload_2021-11-17_16-2-6.png

1 Like

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:

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.

Is running a “Pre-build scripts” my answer? Does that run before the Editor in Unity Cloud Build gets started?

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.

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

#!/bin/bash

rm -r Assets/Oculus

Should do the trick :wink:

Will report a bug later today.

1 Like

Brilliant thanks!