2023.4: Building Unity Games for WebGL

Joseph Youngquist
4 min readJan 5, 2023

--

source: https://labs.openai.com/s/k0ZScKA6tw2UEO3PmvdGssnm

As a consumer of games, having access to play a game without downloading it to my machine and opening up a risk for viruses is a huge benefit. In this article I’ll cover how to go about building for WebGL so potential players of your game can kick the tires before they pull the trigger and make a purchase. I’ll end with a link to one of my first articles here on medium.com on how I automate the building and publishing of my game every time I update my main branch. Lets get it.

Yesterday I covered the build process for Windows, Mac and Linux with a focus on just the Windows process — the other platforms are very much the same, but just selecting them as a target and working with the settings unique to that platform. For WebGL it’s pretty much the same thing.

We’re going to start by opening up the build settings File > Build Settings… or on Windows: Ctrl+Shift+B

Here, I’ve clicked on “WebGL” for the Platform and here’s the settings I’ve opted for. But before we move on, you need to click on the “Switch Platform” button to let Unity prep your game for a WebGL target.

We’re also going to click on the “Player Settings…” button to tweak a few things there as well. As I mentioned in my last article, you may need to adjust the Color Space for your project depending on what Post Processing you have at work. For me, I had to use “Liner”. You’ll find these settings un the “Other Settings” accordion.

The last area in the Player Settings we’ll take a look at is under the “Publish Settings”

When I went through my CI/CD process to automate the build and deployment of my game to my github pages I had a bug that was a little difficult to solve due to how the webpages were hosted, so I had to select “Gzip” for the compression format and I also turned off the “Debug Symbols”. With those tweaks we should be all set to close out the settings window and hit the build button.

One note — if your “Build and Run” button is not clickable, then that means you haven’t clicked on the “Switch Platform” button to have Unity setup your game for WebGL.

As with building for a desktop target, you’ll need to select a folder for the build output. For me, I opted to save to a “webgl-build” — so if I do manually publish somewhere the folder is easier to type out on the server.

Once the build process is all finished, you’ll have a directory full of game assets ready for hosting on your server. And you do have a server right? Well, if not, then go check out my CI/CD article because if you host your code in a GitHub repo, then you totally can host your game for free. I may do a write-up on how to automate the build process and publish to itch.io

Unity also ships with a node server to locally host the build that lets you play your game and test things out. You can play my game on my GitHub hosted page here: https://joseph-youngquist.github.io/space-shooter-pro/

To learn how I publish that game, check out my CI/CD Unity Projects using GitHub Actions

Please let me know if you bump into any issues or have any questions and thanks for the time reading my words :)

--

--

Joseph Youngquist

Veteran to Digital Media publishing, Software Engineering and Architecture starting on a pivot to Unity Development