Doesn't work in 2021.2.3
McSwan opened this issue · comments
So - XMLHttpRequest.js no longer exists where your looking for it.
Not sure how to fix it. I think you'll need to make another template for whatever version of unity they got rid of XMLHttpRequest.js
Error:
Building C:\proj\Builds\HubTemplatetest\MyLoader.js failed with output:
C:\Program Files\Unity\Hub\Editor\2021.2.3f1\Editor\Data\PlaybackEngines\WebGLSupport\BuildTools\Preprocess.js:67
throw "Preprocessor error "" + e + "" occured in file "" + locals.inputPath + "" when evaluating expression "" + expression + """;
^
Preprocessor error "Error: ENOENT: no such file or directory, open 'C:\Program Files\Unity\Hub\Editor\2021.2.3f1\Editor\Data\PlaybackEngines\WebGLSupport\BuildTools\UnityLoader\XMLHttpRequest.js'" occured in file "C:/proj/Test2/HubTest/Assets/WebGLTemplates/responsive-template-2020/MyLoader.js" when evaluating expression " read("UnityLoader/XMLHttpRequest.js") "
(Usenode --trace-uncaught ...
to show where the exception was thrown)
UnityEngine.GUIUtility:ProcessEvent (int,intptr,bool&)
Whoa, only 1 year exactly to get a response :)
It's a bad idea to turn off data caching as that'll mean it'll re-download everything, everytime the user refreshes the web page.
So - XMLHttpRequest.js no longer exists where your looking for it.
Not sure how to fix it. I think you'll need to make another template for whatever version of unity they got rid of XMLHttpRequest.js
Error:
Building C:\proj\Builds\HubTemplatetest\MyLoader.js failed with output:
C:\Program Files\Unity\Hub\Editor\2021.2.3f1\Editor\Data\PlaybackEngines\WebGLSupport\BuildTools\Preprocess.js:67
throw "Preprocessor error "" + e + "" occured in file "" + locals.inputPath + "" when evaluating expression "" + expression + """;
^
Preprocessor error "Error: ENOENT: no such file or directory, open 'C:\Program Files\Unity\Hub\Editor\2021.2.3f1\Editor\Data\PlaybackEngines\WebGLSupport\BuildTools\UnityLoader\XMLHttpRequest.js'" occured in file "C:/proj/Test2/HubTest/Assets/WebGLTemplates/responsive-template-2020/MyLoader.js" when evaluating expression " read("UnityLoader/XMLHttpRequest.js") "
(Usenode --trace-uncaught ...
to show where the exception was thrown)
UnityEngine.GUIUtility:ProcessEvent (int,intptr,bool&)
Solution 1
Download this XMLHttpRequest.js.zip to path from error
C:\Program Files\Unity\Hub\Editor\2021.2.3f1\Editor\Data\PlaybackEngines\WebGLSupport\BuildTools\UnityLoader\
Solution 2
Download this MyLoader.zip to path Assets/WebGLTemplates/responsive-template-2020/MyLoader.js in your project.
Solution 3
Override code like below
Old
#if USE_DATA_CACHING
{{{ read("UnityLoader/XMLHttpRequest.js") }}}
#endif // USE_DATA_CACHING
New
{{{ read("UnityLoader/FetchWithProgress.js") }}}
#if USE_DATA_CACHING
{{{ read("UnityLoader/UnityCache.js") }}}
{{{ read("UnityLoader/CachedFetch.js") }}}
#endif // USE_DATA_CACHING
Old
function downloadBinary(urlId) {
return new Promise(function (resolve, reject) {
progressUpdate(urlId);
#if USE_DATA_CACHING
var xhr = Module.companyName && Module.productName ? new Module.XMLHttpRequest({
companyName: Module.companyName,
productName: Module.productName,
cacheControl: Module.cacheControl(Module[urlId]),
}) : new XMLHttpRequest();
#else // USE_DATA_CACHING
var xhr = new XMLHttpRequest();
#endif // USE_DATA_CACHING
xhr.open("GET", Module[urlId]);
xhr.responseType = "arraybuffer";
xhr.addEventListener("progress", function (e) {
progressUpdate(urlId, e);
});
xhr.addEventListener("load", function(e) {
progressUpdate(urlId, e);
#if DECOMPRESSION_FALLBACK
decompress(new Uint8Array(xhr.response), Module[urlId], resolve);
#else // DECOMPRESSION_FALLBACK
resolve(new Uint8Array(xhr.response));
#endif // DECOMPRESSION_FALLBACK
});
xhr.addEventListener("error", function(e) {
var error = 'Failed to download file ' + Module[urlId]
if (location.protocol == 'file:') {
showBanner(error + '. Loading web pages via a file:// URL without a web server is not supported by this browser. Please use a local development web server to host Unity content, or use the Unity Build and Run option.', 'error');
} else {
console.error(error);
}
});
xhr.send();
});
}
New
function downloadBinary(urlId) {
progressUpdate(urlId);
#if USE_DATA_CACHING
var cacheControl = Module.cacheControl(Module[urlId]);
var fetchImpl = Module.companyName && Module.productName ? Module.cachedFetch : Module.fetchWithProgress;
#else // USE_DATA_CACHING
var cacheControl = "no-store";
var fetchImpl = Module.fetchWithProgress;
#endif // USE_DATA_CACHING
var url = Module[urlId];
var mode = /file:\/\//.exec(url) ? "same-origin" : undefined;
var request = fetchImpl(Module[urlId], {
method: "GET",
companyName: Module.companyName,
productName: Module.productName,
control: cacheControl,
mode: mode,
onProgress: function (event) {
progressUpdate(urlId, event);
}
});
return request.then(function (response) {
#if DECOMPRESSION_FALLBACK
return decompress(response.parsedBody, Module[urlId]);
#else // DECOMPRESSION_FALLBACK
return response.parsedBody;
#endif // DECOMPRESSION_FALLBACK
}).catch(function (e) {
var error = 'Failed to download file ' + Module[urlId];
if (location.protocol == 'file:') {
showBanner(error + '. Loading web pages via a file:// URL without a web server is not supported by this browser. Please use a local development web server to host Unity content, or use the Unity Build and Run option.', 'error');
} else {
console.error(error);
}
});
}
Whoa, only 6 months to ge a response this time. Things are happening at 2x speed :) Thanks
Whoa, only 6 months to ge a response this time. Things are happening at 2x speed :) Thanks
Work?
Not sure - I didn't end up using this template - but it might be helpful for others in the future.