Main game scene not loading?

Hello,
I finished my first WebGL game, and was able to upload it to…

Everything works fine, except my ‘main game’ scene causes the page on my browser to not respond, but in Unity, it works fine. The scenes transition in Unity with no problem. From a browser, my ‘intro’ scene loads perfectly fine and when I click on “Enter password” the scene goes to the ‘password’ scene and when I click the back button, the scene goes back to my ‘intro’ scene. The problem happens when I click on “Play game” from my ‘intro’ scene. Then, the page doesn’t respond and my browser asks me if I want to wait. What could be the cause of that happening? Thank you.

Indeed something is hanging. Can you try to do a Development build, then run in Firefox, and when the “A web page is slowing down your browser. What would you like to do?” dialog comes up, click on “Stop It”. Then open the browser console page and check the callstack that is printed out?

Thank you. I got this…

My game doesn’t even use the ‘i’ key for any input, so I don’t see why ‘Key event not available on some keyboard layouts: key=“i” modifiers=“accel,alt,shift” id=“key_bro’ shows up. ‘Unknown category for SetEventRecordingEnabled: fxmonitor’ is the other error. I googled it, and haven’t had much luck on how to fix it.

That looks like completely else altogether, not related to the hang? When you click on the “Stop It” button, there should be a callstack printed in web page console that shows where the hang occurred.

Piece by piece, I deactivated all my game objects and .cs scripts and rebuilt my WebGL project until my page would respond, and got down to only 1 active game object left in my project. When I disabled the box collider of that one and only game object left in my project, my scene loaded immediately. How can a small simple box collider in a scene effect the whole loading of that entire scene? My ‘intro’ scene has 2 box colliders, and it loaded fine (one that takes the player to the password scene, and another that takes the player directly to the game), but one box collider in the ‘game’ scene causes the whole browser to crash?

I even removed and readded the box collider to the game object, and the same problem reoccurred.

I found out the problem… In Unity, my game uses…

foreach (string file in System.IO.Directory.GetFiles("Assets\\Resources\\Audio\\Footsteps\\"))

to look in that folder for all the .wav or .mp3 files to play whenever the player steps on the floor or the carpet. First, if the player steps on a GameObject that is named “Floor”, my code looks in Assets\Resources\Audio\Footsteps\Floor\ for all the .wav or .mp3 files in that directory, and plays a random file. If the player steps on a carpet, it looks in Assets\Resources\Audio\Footsteps\Carpet\. Somehow, the AudioClip[ ] array that SHOULD contain all the listings of random AudioClips to play, seems to be Null ONLY when I run my game on WebGL (resulting endless recursion to happen in my getMatchingClip() function). Is there a way ‘foreach (string file in directoryName)’ can somehow work in WebGL?.. that when I publish my game into WebGL, the files and folders my game uses get transferred to a ‘virtual file system’ that my WebGL game can access? If not, would that be a nice feature to add?

The ONLY problem WebGL seems to be having, is when it comes to the lines in my .cs scripts in Unity that use…

foreach (string file in directoryName)

It works fine in Unity, but I assume WebGL doesn’t provide access to those files that are used in the Unity ran version of my game. If there is some way to ‘upload’ access to those files (as Unity creates the WebGL platform of my game) when WebGL is ran, that would fix the problem.

I noticed, Resources.Load() works fine in the WebGL platform. One of my GameObjects has a script that reads .txt files from a sub directory in my Resources folder (using ‘resources.Load()’), and my WebGL-ran game doesn’t have problems with that particular GameObject, but the reason I wish to use…

foreach (string file in directoryName)

on other scripts on other GameObjects is because I would like the sounds and textures of some of my GameObjects to be ‘randomized’ simply based on files that I drag and drop from my browser, into a folder, without having to rename each file and program my .cs script to read ‘sound1.wav’, ‘sound2.wav’, ‘sound3.wav’, or ‘texture1.jpg’, ‘texture2.jpg’, ‘texture3.jpg’ etc. Each time I build my game into a WebGL, I would like Unity to automatically take those files and folders from the line ‘foreach (string file in directoryName)’ into consideration AS it builds my WebGL game. Is that a good idea for a new feature?

Hello,
After renaming all my audio files to audio0.wav, audio1.wav, audio2.wav etc. and all my textures to texture0.jpg, texture1.jpg etc. and using Resources.Load() instead, the WebGL runs fine. The game can be played at…

My one and only last problem now is that the Raycasts and ScreenPointToRays are inaccurate (in the browser, ONLY when I run my game in WebGL). An example is, when I click on a clue in the game (on the ground), nothing happens, UNLESS I click right below the clue. On a keypad next to a door, when I click on the buttons on the 9-digit keypad, and I click the ‘8’ button, a ‘5’ gets entered, or when I click on ‘5’, a ‘2’ gets entered. How can this be fixed?

1 Like

Certain sounds from certain objects are also not playing in WebGL. I added a GameObject in front of my camera called “Output” that uses Text Mesh Pro. In the code where sound is supposed to play, I added…

    GameObject.Find("Output").GetComponent<TMPro.TextMeshPro>().SetText(""+ transform.Find("Audio").GetComponent<AudioSource>().clip);

and in Unity, whenever a sound is supposed to play, my Text Mesh Pro object displays the AudioClip that is supposed to play and I hear it, but in WebGL, the Text Mesh Pro object displays the sound that is supposed to play, but I don’t hear anything. Other sounds in WebGL play fine, and I hear them.

I changed all my audio sources to the highest priority (0), and that still didn’t fix the problem of not all my sounds playing in WebGL.

Just to add-on, my understanding is that as WebGL export is, inherently Web-based, you cannot call OS-related namespaces such as System.IO.

Everything that touches files has to go through either Unity’s API or a Web-compatible call.

Yes. I discovered that yesterday, and was able to change the code to load from resources instead.