Unity3D Error with WebGL builds and dfx run locally

I’m progressing with converting my mobile game into WebGL and running it on dfx but I have a new problem: I have managed to get my project converted to a WebGL game and it runs successfully on the following:

Windows 11 - Chrome and Firefox using IIS
Ubuntu 20.04 - Chrome and Firefox using Apache2

I can also get the Unity sample project to run in dfx locally and in the browser. I got the instructions from these two links:

https://internetcomputer.org/docs/current/samples/host-unity-webgl/

https://github.com/dfinity/examples/tree/master/hosting/unity-webgl-template

What I can’t do is get any project, even a simple, brand new WebGL build running on Ubuntu 20.04 (Firefox or Chrome) to run using dfx locally. All I get is a black screen and the following error messages:

Uncaught SyntaxError: expected expression, got '<'DH_WebGL.loader.js:1

Uncaught ReferenceError: createUnityInstance is not defined

h_t_t_p://127.0.0.1:8000/?canisterId=rrkah-fqaaa-aaaaa-aaaaq-cai:27

Has anyone managed to create a brand new WebGL project and get it running on dfx locally without using the sample project? If so, which settings did you use besides setting the compression to “disabled” and the build to “minimal”.

The software versions are as follows:

Ubuntu 20.04
Unity3D 2022.1.20.f1

1 Like

Everybody relax, I solved it :). I was copying the asset files into the directory structure that the example project defined and wasn’t maintaining the directory structure that Unity had defined. Thus, nothing could be found. This became evident once I checked with Chrome’s dev tools.

2 Likes

Manually generating the DFX project is error-prone indeed.
This is why we’re working on a tool named ic-gamekit to help users on this. You can follow the instructions to install the package and have the DFX project generated automatically. Let me know if you have any feedback so we can improve it.

1 Like

Thanks for the link to your package. It works great. I will message you if I have any feedback. I used it to get my game deployed on the IC main-net tonight without any hiccups.

1 Like