Hello everyone ,
Problem
As we know, games developed using Unity 2021.x and earlier can’t be played on Unity Play.
In fact this problem is due to the incompatibility of the new loader codebase with Unity Play platform.
The reason of this incompatibility is that Unity Play assigns “#canvas” as the id of the canvas and at the same time the new loader tries to get the canvas by calling this illegal code.document.querySelector('##canvas')
Fortunately, I have found a way to fix this incompatibility by patching the loader codebase so that the canvas will be got by calling the following code which works like a charm.
document.querySelector('[id="#canvas"]')
In the next section, I will explain how to apply this patch on Windows. The same procedure applies to Mac and Linux too but the installation location will differ.
Patching Steps
https://www.youtube.com/watch?v=-pfsq5S88Zw
- Go to C:\Program Files\Unity\Hub\Editor<UNITY_VERSION>\Editor\Data\PlaybackEngines\WebGLSupport\BuildTools\lib
- Copy DOM.js to your desktop or any other ordinary folder.
- Open the new copy of DOM.js
- Replace every
'#' + (Module['canvas'] ? Module['canvas'].id : 'unity-canvas')
with'[id="' + (Module['canvas'] ? Module['canvas'].id : 'unity-canvas') + '"]'
- Save the file.
- Replace the original DOM.js file with the copy you have modified (Windows may ask for admin permissions to do this action).