unity-game-enginehololensassetbundle

Using Unity 3d asset bundles on Hololens from device folders


We are building a Hololens app which is going to use asset bundles from the device folders, but we are getting a 'Unable to open archive file' error when trying to load the bundle files.

As we don't have much experience with asset bundles we started this by creating a very simple bundle file (just a few Unity primitives and materials) and we made a first try loading them into the app from the Unity editor. That is working as expected but it fails when we deploy the app into our Hololens.

This is our loading method:

#if WINDOWS_UWP
    public async void CallForBundles()
#else
    public void CallForBundles()
#endif
    {
        string bundleFile = "--- NO BUNDLE ---";
#if UNITY_EDITOR
        bundleFile = @"D:\temp\UnityBuilds\AssetBundles\exportablebundle";
#endif
#if WINDOWS_UWP
        Windows.Storage.StorageFolder objectsFolder = Windows.Storage.KnownFolders.Objects3D;
        Windows.Storage.StorageFile bundleFilePointer = await objectsFolder.GetFileAsync("exportablebundle");
        bundleFile = bundleFilePointer.Path;
#endif

        var myLoadedAB = AssetBundle.LoadFromFile(bundleFile);
        //instante bundle components from myLoadedAB//
    }

As you see is something very simple. We find the bundle path by different methods depending on the platform (we already used this system for text files, pngs and others) and the UNITY_EDITOR side is working. The WINDOWS_UWP is throwing this error just on the call to AssetBundle.LoadFromFile(bundleFile);:

Unable to open archive file: C:/Data/Users/edata/3D Objects/exportablebundle

(Filename: C:\buildslave\unity\build\Runtime/VirtualFileSystem/ArchiveFileSystem/ArchiveStorageReader.cpp Line: 542)


'Holoplan.exe' (CoreCLR: CoreCLR_UWP_Domain): Loaded 'C:\Data\Users\DefaultAccount\AppData\Local\DevelopmentFiles\HoloplanVS.Release_x86.jalfonso\System.Diagnostics.StackTrace.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
NullReferenceException: Object reference not set to an instance of an object.
at GameManager.<CallForBundles>d__1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.AsyncMethodBuilderCore.<>c.<ThrowAsync>b__6_0(Object state)
at UnityEngine.UnitySynchronizationContext.WorkRequest.Invoke()
at UnityEngine.UnitySynchronizationContext.Exec()
at UnityEngine.UnitySynchronizationContext.ExecuteTasks()
at UnityEngine.UnitySynchronizationContext.$Invoke1(Int64 instance, Int64* args)
at UnityEngine.Internal.$MethodUtility.InvokeMethod(Int64 instance, Int64* args, IntPtr method) 

(Filename: <Unknown> Line: 0)

"Unable to open archive file: C:/Data/Users/edata/3D Objects/exportablebundle"

seems to be the same error that happens when the app try to load a bunde with wrong file name or path even when running on the editor so it looks like that for some reason 'AssetBundle.LoadFromFile' can't locate de file. We checked the bundleFile at that line and it contains the right filepath ('C:\Data\Users\edata\3D Objects\exportablebundle' where 'exportablebundle' is the bundle file name), so we guess that 'AssetBundle.LoadFromFile' has issues when reading from the Hololens local folder but we don't have much idea about how to address this.

¿Anyone can lend us a hand, please?

EDIT-

We are building our asset bundle with the sample code from the Unity manual in 'Asset bundle workflow'. Is like this:

static void BuildAllAssetBundles(){
  string assetBundleDirectory = "Assets/AssetBundles";
  if (!Directory.Exists(assetBundleDirectory)){
    Directory.CreateDirectory(assetBundleDirectory);
  }

  BuildPipeline.BuildAssetBundles(assetBundleDirectory, BuildAssetBundleOptions.None,  BuildTarget.StandaloneWindows);
}

'StandaloneWindows' as build target seems the closest to hololens from the available list so we went for it.


Solution

  • Sorry, asset bundling isn't working in HL devices right now. It's known issue that has to be fixed.