UnityLoader.js

Anyone know if the UnityLoader.js file is available non-minified as a template so that is can be customised and included in the build each time ?

There’s a few bits i’d like to change to make it more usable for our project but have it built as part of the process rather than needing to manually change it afterwards. Things like localising the language for the error messages and such so not affecting the core loading scripts.

How about using webgl template?
(Unity - Manual: WebGL templates)

It’s not the template that I need to work with. I embed it in to our website already.

The problem is with the minified UnityLoader.js file that is generated from the build rather than the template system.
This has a load of hard coded messages such as the error displays for non compatible browsers like …

and the really helpful

heh

If there’s a pre-build version of this file that Unity uses for the build then could also add my own handling of unsupported browsers etc. without having to edit the generated and obfuscated one each time after a build.

How about writing a customized compatibilitycheck function?

Cheers, I hadn’t seen that custom compatability check one so that would cover part of it.

The other main reason for wanting to find the original version of the loader is that all of the messages, including the loading statuses of downloading, preparing, running etc are all hard coded in English as well. Any thoughts on those ?

You can define your own error handler as well, (also documented in Unity - Manual: Interaction with browser scripting) and use localized strings for that. You could just copy the one from UnityLoader.js, and modify it.

I guess that still leaves the strings printed to the development console. Those are not really meant for end user consumptions, so I’m not sure if there is much value in localizing those?

Hiya, it might be me miscommunicating.

I run a custom template and UnityProgress.js that pulls the loading status messages into the display for the player. We can be running across some slow links so it’s useful for them to see how much they have downloaded, how much is left and what stage of the loader they are at.

This takes the status messages from within the UnityLoader but these are all hard coded in English. There’s a few options for what I wanted to do such as run a script afterwards to search and replace within the file or do some search and replace in the UnityProgress.js.

Obviously it’d be far easier to be able to modify the base UnityLoader.js before it was populated with the build specific info and minified in the same way templates are handled and how I currently do it albeit after the event.

If it’s not available to be modified or if it’s generated from somewhere deeper within then that’s fine, I’ll fudge something up to handle it instead although it would be useful for anyone using a custom loader with text status display. Maybe add it in as part of the module config as well ?

You will find the files you want in PlaybackEngines/WebGLSupport/BuildTools/UnityConfig in your Unity install. Modifying these should work, but it is unsupported, and those changes will be local to your Unity install. There is no way to override these files in your project.

1 Like

Great stuff.
Thanks for that Jonas.

For anyone else looking it appears the various texts that are displayed when working off a custom loader base, (such as Unity WebGL Custom Progress Bar - Alex Ocias Blog ), are in the following files.

“Preparing…” - UnityModuleSetup.js
“Downloading (0.0/1)” - UnityModuleSetup.js
“Downloading data… (” - decompress.js
“Downloading data…” - decompress.js
“Running…” - Emscripten\postamble.js

If you make a development build the UnityLoader.js file will be non-minified.

2 Likes

can we change unityLoader.js after build unity webgl application with some minnor changes in file is applied in project or not

So please friends Help me Out.

Yes. Check Unity - Manual: Build Player Pipeline and you can do whatever you want by executing your own scripts after builds then do what you need them doing.

How i can pass the parameters in unity WebGl using wegconfig or appconfig after buide

Write a C# editor script that does what you want to achieve. Have that be triggered after Unity finishes a build as described in the manual.

I removed gzip and brotli decompressors from UnityLoader.js. Also I did not find any using of
UnityLoader.Cryptography.crc32 or UnityLoader.Cryptography.sha1.
My min file is 39kb instead of 155kb now.

Initial loading of web page is pretty important thing to ignore.

Can you share your new UnityLoader.js?

https://gist.github.com/kyptov/f7e4718ee93b5c42bb975bc006fb10b4

1 Like

Go to your gameInstance inside index.html after build then paste the same code after
var gameInstance = UnityLoader.instantiate(“gameContainer”, “pathTo Your Json File”,Replace This With The Code down below);

Code To Paste:
{
compatibilityCheck: function (unityInstance, onsuccess, onerror) {
if (!UnityLoader.SystemInfo.hasWebGL) {
unityInstance.popup(“Your browser does not support WebGL”,
[{text: “OK”, callback: onerror}]);
} else if (UnityLoader.SystemInfo.mobile) {
onsuccess();
// unityInstance.popup(“Please note that Unity WebGL is not currently supported on mobiles. Press OK if you wish to continue anyway.”,
//[{text: “OK”, callback: onsuccess}]);
} else if ([“Edge”, “Firefox”, “Chrome”, “Safari”].indexOf(UnityLoader.SystemInfo.browser) == -1) {
unityInstance.popup(“Please note that your browser is not currently supported for this Unity WebGL content. Press OK if you wish to continue anyway.”,
[{text: “OK”, callback: onsuccess}]);
} else {
onsuccess();
}
},

});

The application loading speed of webgl platform is very slow after it is released. The main drag on the speed is the file untiyweb. Does anyone have a solution

Turn on data caching