Loading an asset on HoloLens only works in Unity?

915 Views Asked by At

I am developing a HoloLens-Application that loads assets from its internal memory. At the moment I can just access the Emulator and not the device.

    try
    {
        //for unity: replaced with string path = @"C:\Users\root\Desktop\cube";
        string path = Path.Combine(Application.persistentDataPath, "cube.unity3d");
        if (File.Exists(path))
        {
            //Using the example code
            myLoadedAssetBundle = AssetBundle.LoadFromFile(path);
            if (myLoadedAssetBundle == null)
            {
                Debug.Log("Failed to load AssetBundle!");
                return;
            }
            var prefab = myLoadedAssetBundle.LoadAsset<GameObject>("cube");
            Instantiate(prefab);
            myLoadedAssetBundle.Unload(false);
        }
        else
        {
            //do nothing
        }
    }
    catch (Exception ex)
    {
        //never reached during all tests
        Debug.Log(ex.Message);
    }

When I press the play-button in unity, the cube is displayed, but when I run the program in the HoloLens-emulator, it just does not work. The file exists, but the myLoadedAssetBundle is always null. In Unity I used the path to the desktop, when running on hololens I used the path in the code. All files can ber accessed. Even the following worked fine:

//called after creating the string path
File.WriteAllText(path + ".txt", "This is a test");

I have no idea what could be the problem. The file always was in the path (I uploaded it in FileExplorer) and it was found. The file on my desktop is exactly the same as the one uploaded in the emulator.

Are there any chances that it runs on the HoloLens but not on the emulator?

Update:

Now I also tried it on a real HoloLens with the same Issue. I am using Unity 2017.1.0f3

1

There are 1 best solutions below

0
On

I struggled with this for a while too.

I found it to be related to how the asset bundle is exported. Examples tend to show this -

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

But in order to work in the HoloLens they need to be exported like this -

BuildPipeline.BuildAssetBundles(assetBundleDirectory, buildMap, BuildAssetBundleOptions.None, BuildTarget.WSAPlayer);