Skip to content
/ UnityWebGLTemplate Public template

A template repo you can use to push your Unity WebGL games to Github pages

License

Notifications You must be signed in to change notification settings

Bwc9876/UnityWebGLTemplate

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

31 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

UnityWebGLTemplate

A template repo you can use to push your WebGL games to GitHub pages.

Uses:

Example Repo

How it Works

Whenever you merge a pull request, GitHub will automatically compile your game using Unity to WebGL, the resulting build files will then be pushed to the gh-pages branch.

Setup

Template Cloning

In the top right, select "Use this template", in the subsequent screen ensure that you select "Include all branches" or else the workflows won't work.

Clone the template

Generating Project Files

Open Unity Hub, create a new project and set up whatever options you need to. Once the project is created close unity.
Now open GitHub desktop, clone the repo into any folder.

Copy the following folders from the Unity Project folder to the Git repo folder:

  • ProjectSettings
  • Assets
  • Packages

Once these are copied, delete the Unity Project folder and remove it from Unity Hub. Finally, open the Git repo folder in UnityHub as a project.

Now the unity project folder and the git repo folder have been merged successfully.

Versions

First things first, you're going to want to go to activate.yml and edit "unityVersion" on line 13 to your target unity version.
You're also going to want to do this in main.yml on line 44.

License

Now, go to the "Actions" tab of this repo and select "Acquire activation file" in the left plane and click "Run workflow", then run it on the main branch. This will create a license request file as an artifact, to access this file click "Acquire Activation file" in the list of actions, and wait for the action to complete

Run Acquire activation action

If all goes well, there should be an artifact available to download with the name Unity.your_unity_version.alf, download this file to your local machine.

Download artifact

Once downloaded, head to https://license.unity3d.com/manual. There, you will upload your .alf file, and retrieve a .ulf file. Now you need to go to the Settings tab of your repo, click on "Secrets" on the left, and add a secret named "UNITY_LICENSE" with the contents of your .ulf file. This will allow the unity builder action to run unity installations.

After this step is done, it is safe to delete activate.yml

Changing versions will require you to repeat this step!

Important note about compression

GitHub pages does not allow for you to configure HTTP response headers for compression; so, you'll need to disable it in player settings.
Head to Edit > Project Settings > Player > Scroll down to "other settings" > Click the dropdown labelled "Compression Format" and select "Disabled".
Also check the Decompression Fallback option.

Try It Out

Now that your Unity license is setup, make a PR and merge it to your main branch, as long as the PR affects the game (stuff like the README and .gitignore won't trigger a build) the build action will start. Once the action finishes, open the page through the "deployments" section on the right side.

Config

By default, unity builder won't run if the branch is 'dirty'. This means that you've directly edited the main branch and didn't use a Pull Request. to mitigate this, uncomment line 45 in main.yml.

To enable the ability to build manually (without having to push), uncomment line 20 in main.yml.

Post-Setup

After setup you should delete this README file in favor of your own, the images folder can also be deleted.

Optional Steps

Integrate With Discord
Customize WebGL Template
Integrate a Testing Suite
Setup your own Runner for Faster Builds
Use a custom pull-request template
Use Git LFS (Edit your .gitattributes)
Add a Status Badge
Use a custom domain

About

A template repo you can use to push your Unity WebGL games to Github pages

Topics

Resources

License

Stars

Watchers

Forks