A template repo you can use to push your WebGL games to GitHub pages.
Uses:
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.
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.
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.
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.
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
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.
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!
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.
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.
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.
After setup you should delete this README file in favor of your own, the images folder can also be deleted.
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