CodeNewbie Community

Dhruv Mehta
Dhruv Mehta

Posted on

Host your Unity Games online for free using GitHub

Originally written here on the DEV.to website.


Did you know that you can actually host your Unity games on GitHub using GitHub Pages โ“ โ“

And if you want to know how, then continue reading this article... ๐Ÿ‘‰


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 ? ๐Ÿ’ก

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.


๐ŸŽฎ 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

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

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


What are GitHub Pages? ๐Ÿ’ก

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.


๐Ÿ’ป 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

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

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


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! ๐Ÿ˜„


Some important links :

Discussion (0)