Deploying your Unity Game on Azure
Vivek Singh
Senior Cloud TSE- Infra & Ops | Cloud Solutions Architect | Microsoft Certified Trainer
In recent times, for game developers it is really necessary to design and deploy their games in a highly available and robust environment. This environment should provide developers flexibility and agility to integrate latest emerging technologies into their applications. This platform should also provide detailed application usage analytics and various insights as desired. These insights are very critical in terms of the required application specific optimizations for refining application deployments and to analyse the underlying costs of running the application workload on cloud.
Azure provides Unity game developers a very application friendly and highly scalable platform to host their games. It gives them an option as well, to evaluate numerous enterprise class technologies, which are available on Microsoft's cloud platform.
This article will guide you through the process of hosting and running your Unity application workloads on Azure.
Prerequisites:
- Unit Game Engine (Version 2019.3.15f1 Personal)
- Microsoft Visual Studio Community 2019 (Version 16.6.1)
- Azure Subscription
Note: Along with all this, basic knowledge of Azure and Unity Game Engine is required for successfully hosting and running the Application.
Step 1: Creating a Unity WebGL game build
1. Launch Unit Game Engine and Open your Project consisting Game that you are planning to host on Azure.
2. Go into your game in Unity Game Engine and click on FILE and then BUILD SETTINGS.
3. Under Platform option, if a different option is selected, click on WebGL option, then Click on Switch Platform option.
4. Once platform is switched to WebGL, select all the required game scenes and then Click on BUILD.
5. Next select or make a folder to store the WebGL version of your game (click on SELECT FOLDER once you have done that). Do not build it inside your existing Unity Project folder.
6. Once build is ready, edit your Web.config file (file along with index.html) in the root directory of the game Build and replace with following code-
<configuration> <system.webServer> <staticContent> <remove fileExtension=".json"/> <mimeMap fileExtension=".json" mimeType="application/json; charset=UTF-8"/> <remove fileExtension=".unityweb"/> <mimeMap fileExtension=".unityweb" mimeType="application/octet-stream"/> </staticContent> </system.webServer> <system.web> <compilation debug="true"/></system.web> </configuration>
Step 2: Testing and Publishing your game build to Azure by using Visual Studio.
1. You can connect directly to Azure using Visual Studio 2019. Open Visual Studio and go to the FILE menu, select NEW and then click on Project. Then in the Create new project window, search for ASP.NET Web Application (.NET Framework). Here Select option with C# support.
2. If you haven’t already installed it click on Open Visual Studio Installer and install the ASP.NET and web development and Azure development workloads.
3. Select ASP.NET Web Application (.NET Framework) as your project type and choose the folder where your Unity WebGL version of your game is located. Then click on Create.
4. In the next Window select EMPTY option and finally click on Create.
5. Once Project is created Click on FILE, then select OPEN and finally click on Web Site option.
6. Then navigate to your game build location and Select the Build directory.
7. Once build files are loaded, click on the BUILD menu and select Publish Web App .
8. Select Azure as the publish target and click Next.
9. Then Select Azure App Service (Windows) as a Specific target and Click Next.
10. On the next screen make sure you are logged into the Microsoft account that is linked to your Azure account. If you are not click on your account details in the top right-hand corner and choose to add an account. Log in with the account that you linked to your Azure account. Then Click on Create New App Service.
11. Create a new Azure App Service (Windows) with desired Name, Resource Group and App Service Plan. Then Click on Create.
12. All web apps that you are hosting should appear in the box, choose the one you just created to publish your game to and click on Finish.
13. The Publish Preview window should be automatically filled in for you. Finally, just click on Publish to host your Unity Game on newly created App Service.
Step 3: Test your Game hosted on Azure App Service
1. Your game should now be uploaded to your Azure Web App. If it is successful it should open a web browser automatically with the URL of your game to allow you to test it.
2. If you have done everything right you can now go onto a web-browser, enter the URL for your web app and it should run within the browser. You can also just click on the URL in the Azure portal for your web app to go to it.
3. You can Monitor usage of the Application through your Azure Portal as well and also get all the desired Insights.
Finally, we have successfully deployed Unity Game Application on Azure App Service. Feel free to evaluate my test Unity Application by clicking on below link and let me know your feedback in the comments.
Thank you!
Computer Engineer
2 年Hello Vivek, thanks for the tutorial! I've a question, Can I set more than one build in this website, so I can access each game by their custom route. Example: mydomain.com/game1, mydomain.com/game2?
Senior Software Engineering Manager at Pariveda Solutions (AI/ML, Data, and Cloud Architect; Healthcare SME)
3 年Great article, thanks for the content!
Scientific Programmer at Griffith University
3 年?? Thanks!
Software Engineer
3 年This did not work for me. First I had issues related to the .wasm file, which Luis Aldair Gutierrez Villalobos comment led to me fixing, but afterwards it was a bottomless pit of one issue after the other, mostly related to not being able to find or load the build files. (Unity also does not automatically generate the web.config file at all for me, there is an example here that seems to cover a lot of bases https://docs.unity3d.com/Manual/webgl-server-configuration-code-samples.html) However even after figuring that out and getting past the "both async and sync fetching of the wasm failed" error that plagued me for hours, I just could not get the app the load on the Azure Web App service, even though I am currently hosting an API server and a Database for this same project there fine. The last issue I had before giving up was it throwing a "createUnityInstance is not defined" error. I eventually gave up and got the project running on github pages in 2 minutes with zero issues or hassle.