Developing, building and distributing a game for Windows UWP in Unity 3D 2017.x
Recently we entered our game, The Forbidden Arts, into the Windows Dream Build Play contest. One of the requirements for entry was to build and publish the game on the Windows UWP platform, although it isn't required to be live in the store. We didn't have the smoothest ride, but we did make it to the end of the road. I'm writing this Blog to help other developers who might be struggling to port your Unity game to Windows UWP. At the time of writing, we were using Unity 2017.2.1 and Visual Studio 2017.
First let's begin in Unity. Most of The Forbidden Arts' code is compatible with Windows UWP, but there are some parts of .NET that are not. Be prepared to change some of your code. For example, System.Reflection is not supported in UWP development. We had to rewrite any code which used System.Reflection, but it wasn't the biggest deal. Just take note you will likely encounter errors with your game and have to fix them before proceeding to port the game. This of course, depends on the complexity of your game and what your code looks like.
Make sure to build your game with VSYNC turned ON. We figured this out with a lot of trial and error, but caught the issue by using the Unity Profiler. If you don't use VSync, your game will likely screen tear, or appear laggy or choppy at times, while running in UWP. UWP requires VSync for your game to run smoothly. I believe it has something to do with targeting mobile devices that typically do require VSync. VSync is located in Unity's Quality settings. You can also manually make this call in your script's Start method to ensure VSync is forced on:
QualitySettings.vSyncCount = 1;
Before you build your app, you should make sure you're updated to the latest version of the Windows Development Tools as well as the latest version of Visual Studio 2017. Using the latest versions of everything was the only way we could get a functioning build, so even though you might be able to get things to work with other versions, we are going to recommend using the latest updates.
Once VSync is on, your code compiles in Unity, and you have the required build tools installed in your system, you're ready to build. Our game is written in C#, so if your game was written in another language these next steps might not be relevant to you.
Above is a screenshot showing our exact build settings. The important thing to note is that you should set build type to XAML and Check the box "Unity C# Projects."
Next go to Player Settings.
For the Icon tab, we left this completely blank, and just filled in the title of the game, The Forbidden Arts. For the Splash Image, we have a custom splash screen using Unity's built in functionality. You can see our settings below:
In "Other Settings" tab you can view our settings below. Make sure you choose the appropriate .NET compatibility level and runtime version, as noted with our settings.
Finally we get to the Publishing Settings tab. Please note our screenshot below. Microsoft requires your first version published to be 18.104.22.168 or higher so just put that in the version # if it's your first time. You cannot publish with a pre-1.0 version of your game, even though ours technically was. You will need to have a valid certificate for your game so click the Create button to create one if you have not already done so.
Now that you've configured your build and player settings, you can build the game. Once your game builds, it's time to enter Visual Studio. Open up the .sln file to launch Visual Studio.
Once inside you will need to set the build settings inside visual studio. For our build, we are targeting a "Master" build for 64 bit operating systems as we are only targeting desktop platforms. For distributing your build to the Windows Store, you need to select the Master build. Don't even bother with a debug build because it's extremely laggy and will not reflect how well your game actually runs. Debug builds are good for building standalone in Unity, but not in Visual Studio. Just save yourself a headache and select Master.
Once you set your build settings, you will need to define your certificate. Originally we thought that by creating a certificate in Unity it will automatically apply it in Visual Studio. The short answer is no, it will not. In order to apply the certificate you need to open the file Package.appxmanifest, as shown in the screenshot below.
Click the Packaging tab and make sure your version number reads 1.1.0 or higher depending on whether this is your first build you are uploading to the store. You will need to click the button "Choose Certificate" to choose your certificate for signing the app. Click the drop down menu labeled "Configure Certificate" and select "Pick from Certificate Store." Assuming you generated a certificate in Unity it should appear here. Just hit "Ok" and you're properly set up to sign your app.
Save your changes and close the manifest file.
Assuming you've done everything correct to this point, you can now build your app. Choose Build > Build Solution.
Once the solution is built, you should test it by selecting Build > Deploy Solution. If the app plays smoothly and all looks good you're ready to upload to the store.
The next step is to choose Project > Store > Associate App with the Store. Follow the instructions and make sure your app is properly associated. You can then build a package. Select Project > Store > Create App Packages.
Select your settings and notice the output location.
This is important. We recommend just leaving the Output Location as the default location Visual Studio suggests. Hit Create and your package will be created.
Once your app package is created, you can now exit out of Visual Studio. The final step is to log in to your Microsoft Developer Account and upload your app package. Go ahead and navigate to where your package was created. In our case it was in the Forbidden Arts folder under App Packages.
The file you want to upload is the Appxupload file.
Assuming you get no errors when uploading, you're finished and can submit your app to the store. Congratulations! We hope this post helped.