- Home /
Problem with loading asset bundle in WebGL build
I built a scene into an asset bundle using the following piece of code:
BuildPipeline.BuildAssetBundles(/*local bundle path*/, BuildAssetBundleOptions.ChunkBasedCompression, BuildTarget.WebGL);
Then I uploaded the extensionless asset bundle file (not the manifest file) to my google drive and got the download link. Now when I try to download and load the scene, it works in the editor but not in the WebGL build when I run it locally in Edge. Note that I also deleted all these files which appeared after the asset bundle building from my computer, and also cleared the scene, its dependecies (one texture) and meta files from the project folder to make sure the editor really gets the bundle from the drive. The code I use to download the bundle and load the scene in it is as the following:
IEnumerator DownloadAndSetUpSceneBundle()
{
var uwr = UnityWebRequestAssetBundle.GetAssetBundle(@bundleURL);
yield return uwr.SendWebRequest();
AssetBundle assetBundle = DownloadHandlerAssetBundle.GetContent(uwr);
string[] scenePaths = assetBundle.GetAllScenePaths();
Debug.Log(scenePaths[0]);
string sceneName = Path.GetFileNameWithoutExtension(scenePaths[0]);
SceneManager.LoadSceneAsync(sceneName);
}
It all works perfectly in the editor, but when I run the build locally using Edge, I get the following errors in the console:
SEC7120: [CORS] The origin 'file://' did not find 'file://' in the Access-Control-Allow-Origin response header for cross-origin resource at 'https://drive.google.com/u/0/uc?id=1iojUlUnleSAb_E4RFHTaooTC4iYiD7-n&export=download'.
Asset Bundle download is complete, but no data have been received
Please help me. Thanks in advance!
Answer by simetra · Jun 24, 2020 at 08:36 AM
As opposed to what Unity claims, this is NOT the best place for answers, not at all. It seems like people mostly dont care about questions of others, they just seek answers. Anyway, if you have the same problem as me, this is a cross-origin problem, meaning the WebGL game or web app is situated at domain-a.com while the asset bundle u are trying to download during runtime is located at domain-b.com which is not allowed by domain-b by default. You wanna have your bundle under the same domain as your web game/app, otherwise u have to permit the cross-origin access for domain-a in the source code of domain-b but I am not familiar with web development so go check that out yourself.
Answer by Jon_Olive · Jun 25, 2020 at 09:13 AM
I've just had a very similar problem - though in my case the site the asset lives on is mine - so I was able to edit the .htaccess file to allow the cross origin resource sharing.
Answer by williamfalvo · Jun 25, 2020 at 09:24 AM
Hi, you have to place the AssetBundles folder in the same place of the site.
For example if your WebGL site is into "http://www.example.it" url , so you can search and have to place your AssetBundles into "http://www.example.it/AssetBundle/ASSETNAME"
Your answer
Follow this Question
Related Questions
WebGL build crashes but game runs fine in editor and windows build. 0 Answers
How to prevent large font from increasing build size and load time of WebGL by 100% 0 Answers
Unity Cloud Build with Addressables for WebGL 0 Answers
UI image rendering on some devices but not others 0 Answers
Using CachedXMLHttpRequest 1 Answer