Hosting Unity Games on Hugging Face Spaces
Hugging Face Spaces, while primarily designed for Machine Learning demos, can be used to host and share playable Unity games. This is achieved by leveraging the Static HTML template and Unity's WebGL build capabilities.
Deployment Workflow for Unity Games
Hosting a Unity game on Hugging Face Spaces requires a specific build and upload sequence to ensure the game renders correctly in a web browser.
Space Configuration and Local Setup
To begin, users must create a new Space on Hugging Face and select the Static HTML template. Once the Space is created, it should be cloned to a local machine using Git:
git clone https://huggingface.co/spaces/{your-username}/{your-space-name}
Unity Build Settings
To make a Unity project compatible with Hugging Face Spaces, the following configuration changes are required within the Unity Editor:
- Build Target: Navigate to
File > Build Settingsand switch the target platform to WebGL. - Compression Format: In the Player Settings panel under the Publishing Settings section, the Compression Format must be set to Disabled.
Optional Visual Customization
Hugging Face provides a dedicated Unity WebGL template to improve the game's appearance within the Space. To use it, the repository is added to the project files, and the template is selected under Player Settings > Resolution and Presentation.
Uploading the Build
Once the project is built for WebGL, the resulting files from the build folder must be copied into the cloned Space repository. Because Unity build files can be large, Git Large File Storage (LFS) must be enabled to track the build directory:
git lfs install
git lfs track Build/*
Finally, the changes are pushed to the Hugging Face repository using standard Git commands (git add, git commit, and git push).
Examples of Unity Games in Spaces
Several projects demonstrate the viability of this hosting method, including:
- Huggy: A playable demo hosted on Spaces.
- Farming Game: A Unity-based simulation.
- Unity API Demo: A technical demonstration of Unity's capabilities within the environment.