Deploying your Unity Game on Azure

Deploying your Unity Game on Azure

No alt text provided for this image

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.

No alt text provided for this image

2. Go into your game in Unity Game Engine and click on FILE and then BUILD SETTINGS.

No alt text provided for this image

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.

No alt text provided for this image

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.

No alt text provided for this image

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.

No alt text provided for this image

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.

No alt text provided for this image

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.

No alt text provided for this image

4. In the next Window select EMPTY option and finally click on Create.

No alt text provided for this image

5. Once Project is created Click on FILE, then select OPEN and finally click on Web Site option.

No alt text provided for this image

6. Then navigate to your game build location and Select the Build directory.

No alt text provided for this image

7. Once build files are loaded, click on the BUILD menu and select Publish Web App .

No alt text provided for this image

8. Select Azure as the publish target and click Next.

No alt text provided for this image

9. Then Select Azure App Service (Windows) as a Specific target and Click Next.

No alt text provided for this image

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.

No alt text provided for this image

11. Create a new Azure App Service (Windows) with desired Name, Resource Group and App Service Plan. Then Click on Create.

No alt text provided for this image

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.

No alt text provided for this image

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.

No alt text provided for this image


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.

No alt text provided for this image

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.

No alt text provided for this image

3. You can Monitor usage of the Application through your Azure Portal as well and also get all the desired Insights.

No alt text provided for this image

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!


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?

回复
Sofia T.

Senior Software Engineering Manager at Pariveda Solutions (AI/ML, Data, and Cloud Architect; Healthcare SME)

3 年

Great article, thanks for the content!

John Zhong

Scientific Programmer at Griffith University

3 年

?? Thanks!

Andy Hoffman

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.

回复

要查看或添加评论,请登录

Vivek Singh的更多文章

社区洞察

其他会员也浏览了