We have customers who are seeing Unity not start when Chrome updated to 112. I’ve done some preliminary investigation and found that it seems to be mostly effect Chromebooks running old Celeron processors and it seems to be failing when trying to create a context that has the attribute "premultipliedAlpha":false
. It effects all WebGL projects, not just Unity builds.
Since this doesn’t seem to be Unity’s fault per se, I’d like some help to figure out how to hijack the UnityModule and prevent it from setting that attribute. It’s causing a lot of problems. I’ve done a grep in the Unity code and in my Project and can’t find that phrase, so it must be in a binary file somewhere. Could I get some assistance?
For anyone else who may be running into this issue, if you go on to your build machines and go to your Unity install location/WebGL Support/BuildTools/Emscripten/src there is a file called library_html5.js
. In there if you scroll down to line 2157 for my version, but you’re looking for a function that is setting up an array of attributes for createContext. In there I added these lines:
console.log(“Overiding Unity default premultipliedAlpha”);
contextAttributes[“premultipliedAlpha”] = true;
Note, if your application relies on blending with the canvas, it won’t work anymore. Hope this helps anyone else stuck here. It’s a very hacky fix, and I’m assuming Chrome will fix it eventually. Here’s the Chromium ticket if they ever do: Google Issue Tracker
1 Like
We’ve encountered the same issue where our games fail to start on Chromebooks that run ChromeOS 112. Your proposed temporary solution does fix the problem, but there’s a simpler way to enable premultipliedAlpha without the need to delve into the compiler.
You can easily overwrite the WebGL’s Context Attributes in the createUnityInstance method. Simply provide the webglContextAttributes object to the UnityParameters and overwrite the required attributes. You can find more attributes that can be overwritten by visiting WebGL Rendering Context | React Unity WebGL.
Here’s an example of how to implement it in the createUnityInstance method:
createUnityInstance(someCanvasReference, {
dataUrl: "unitybuild/module.data",
frameworkUrl: "unitybuild/module.framework.js",
codeUrl: "unitybuild/module.wasm",
// Add the `webglContextAttributes` object to the UnityParameters
webglContextAttributes: {
// Overwrite the required attributes
premultipliedAlpha: true,
},
});
1 Like
jeffreylanter’s solution is for Unity 2020 and above. For older versions of Unity, use this syntax:
gameInstance = UnityLoader.instantiate("gameContainer", "Build/release.json", {
Module: {
webglContextAttributes: {
// Overwrite the required attributes
premultipliedAlpha: true,
preserveDrawingBuffer: false,
},
},
});
I’m wondering if there’s a performance impact to using the premultipliedAlpha workarounds noted above, …I mean if we want WebGL builds working on the broken Chromebook Chrome versions, is it safe/performant just to enable premultipliedAlpha always, or should there be Chrome OS detection + Chrome browser detection (if Chromebooks run other browsers - I don’t know anything about them)?
A quick idea based on pages here and here I thought the below approach might work, but maybe it could be improved further with a version test so older versions could still run without the [potential] overhead of the workaround - does anyone have a tested/working approach to solve this conditionally? I don’t have a Chromebook or know anybody with one, so I can’t test this myself… but maybe as a way to specifically target only that browser:
premultipliedAlpha: (/\bCrOS\b/.test(navigator.userAgent) && Boolean(window.chrome))