Search Unity

Running into the 'Unable to open archive file' error when loading AssetBundle on WebGL build

Discussion in 'Asset Bundles' started by MBezzina, Jun 15, 2021.

  1. MBezzina

    MBezzina

    Joined:
    Jan 6, 2021
    Posts:
    6
    As the title explains, I'm trying to set a variable using the AssetBundle.LoadFromFile() method and am encountering the error 'Unable to open archive file: filepath'. When I click on my filepath link in the Console, it downloads the file I expect and is seemingly just not setting my loadedAssetBundle variable properly.

    I currently have prefabs labeled under the AssetBundle(s) I'm trying to save, but have also tried simple scenes (ie just a cube) and simpler prefabs as well. I get the same error every time and have been halted by this issue. I've posted some images of my code and the console error as well to help clarify how it's set up. Any help / advice is very much appreciated. Thanks!
     

    Attached Files:

    mmaynard_ml likes this.
  2. MBezzina

    MBezzina

    Joined:
    Jan 6, 2021
    Posts:
    6
    FIX: I believe the issue was solved by first bringing in the file as a UnityWebRequest and then using DownloadHandlerAssetBundle.GetContent() to turn it into a usable AssetBundle. Here's the change that seems to have cleared up the issue.
     

    Attached Files:

    mmaynard_ml likes this.
  3. Yum1994

    Yum1994

    Joined:
    Jul 19, 2016
    Posts:
    5
    I ran into this same problem and the search engine brought me here. It is true that AssetBundle.LoadFromFile is using file system and on WEBGL the way to find a resource is by URL scheme. So, the change from LoadFromFile to UnityWebRequest can make use of URL scheme and successfully find the file you want.
     
    AndrewSkow likes this.
  4. AndrewSkow

    AndrewSkow

    Unity Technologies

    Joined:
    Nov 17, 2020
    Posts:
    91
    Yes, on WebGL the AssetBundles can be requested via UnityWebRequest.

    Instead of the AssetBundle cache available on other platforms this topic discusses caching:
    https://docs.unity3d.com/2023.3/Documentation/Manual/webgl-caching.html

    Note that in order for an AssetBundle to be loaded it needs to be expanded into memory, in either LZ4 or Uncompressed format. So distributing LZMA compressed AssetBundles would not be very efficient on WebGL as the conversion would happen each time it is loaded even when it is cached on the device.