Host your Unity Games online for free using GitHub 
Tags: unity3d, gamedev, github, html
Published: 2021-03-12 22:33:06

### Did you know that you can actually host your Unity games on GitHub using GitHub Pages :question: :question:
> ### And if you want to know how, then continue reading this article... :point_right:

---

#### But before we get started let me tell you the prerequisites for hosting your games:

> 1. Unity WebGL Build 
> 2. GitHub account for GitHub Pages (yes we will be hosting the game using GitHub pages)

---

### So what is WebGL ? :bulb:
> Unity’s WebGL build allows you to render 2D and 3D graphics in a web browser without the need for additional tools or plug-ins. When you publish a WebGL build, Unity builds a HTML5/Javascript program. 

---

## :video_game: Building a Unity game into WebGL form : 

**Step 1 -** In your Unity Game Engine (when you are ready with your game) : _Click on File > Build Settings_ 
![FiletoBuild](https://raw.githubusercontent.com/Dhruv-194/HostUnityGamesonGithub/main/Screenshot%20(109)_LI.jpg?token=AOSOBHCV5PDSHTTAVOFX55TAKPN3C)

**Step 2-**  In the Build Settings - 
* Add all your game scenes. 
* In the platform section: _Choose WebGL > Switch Platform_  (this step is necessary when you are using WebGL for the first time) It will take sometime to convert your game's platform.
* After this _Click on > Player Settings..._ and do the necessary changes for your game like - Product Name, Game's Resolution, adding/removing Splash Screen etc. 
* _Click > Build_ and you are good to go. It will ask you where to put your game files and create a _"WebGL Build folder"_ for you. 
![Build Settings](https://raw.githubusercontent.com/Dhruv-194/HostUnityGamesonGithub/main/Screenshot%20(110)_LI.jpg?token=AOSOBHAMRRDLDOQ7VRJQOP3AKPPCQ)

**Step 3-** It will create some folders and files in your _"WebGL Build folder"_ which will have some folders like _Build, Template Data and index.html file_ (as shown in image below)
![WEbGL Build Folder](https://raw.githubusercontent.com/Dhruv-194/HostUnityGamesonGithub/main/Screenshot%20(112).png?token=AOSOBHAGVZ5B4OMACO3PATTAKPPXQ)

--- 

### What are GitHub Pages? :bulb:
> GitHub Pages is a static site hosting service that takes HTML, CSS, and JavaScript files straight from a repository on GitHub, optionally runs the files through a build process, and publishes a website. 

---

## :computer: Hosting the game using GitHub Pages: 

**Step 1 -** _Sign in into your GitHub account > Create a new repository > Add all your files from the "WebGL Build folder" to this repository_ (as shown in the image below) 
![github repo](https://raw.githubusercontent.com/Dhruv-194/HostUnityGamesonGithub/main/Screenshot%20(113).png?token=AOSOBHASZEWDTY4EZMCS3R3AKPSAK)

**Step 2 -** Now _Click on Settings > Go to the bottom of the page where you can see "GitHub Pages"_ 

**Step 3 -** Now you need to provide a source to GitHub for hosting your game as a GitHub Page. To do so, below Source _Click on None > Choose "main" branch_ (the branch where you have committed your files). 
![githubpages](https://raw.githubusercontent.com/Dhruv-194/HostUnityGamesonGithub/main/Screenshot%20(114)_LI.jpg?token=AOSOBHHPUABPEPHJIJVH5DDAKPSSG) 

**Step 4 -** After this _Click > Save_ and you are done! You will get a message that your site is published and you will get the URL of it as well (as shown in the below image). 
![published](https://raw.githubusercontent.com/Dhruv-194/HostUnityGamesonGithub/main/Screenshot%20(115).png?token=AOSOBHGHAJSMZBTT3XGP5EDAKPS4I)

--- 

> So there you have it !! An easy way to host your Unity based games on the web for free, for you and your friends to play. This option opens to many possibilities which you can try like - making your games more accessible, testing your games before the final release, adding them to your online portfolio etc. 

---

### Lastly if you guys liked my article then do react to it. And in the discussions down below do add the URLs of your hosted games. 
### Thank You for reading! :smile:

--- 

> ### Some important links : 
- [Learn more about Unity WebGL](https://learn.unity.com/tutorial/how-to-publish-for-webgl#:~:text=0-,Unity%27s%20WebGL%20build%20allows%20you%20to%20render%202D%20and%203D,access%20in%20a%20web%20browser.)
- [Learn more about GitHub Pages](https://docs.github.com/en/github/working-with-github-pages/creating-a-github-pages-site)
- [My GitHub repository which I used in this article](https://github.com/Dhruv-194/BoxShooterGame)
- [My hosted game for your reference](https://dhruv-194.github.io/BoxShooterGame/)