Unity output to UWP
Unity is a cross-platform game engine. When we want to export our game to Windows Store, it will show you a bunch of errors. The article below is some notes about the process for exporting Unity game to UWP (Universal Windows Platform).
I use Visual Studio 2015 and Unity 2018.2.1.f1 in this note.
Prerequisites
- Visual Studio 2015 Tools for Unity
UWP Build Support (IL2CPP)
which can be checked when installing Unity.UWP Build Support (.Net)
have some problems and will be deprecated soon.Windows 10 SDK
which can be downloaded when installing or modifying Visual Studio.- Purchase a Microsoft Store account.
Build
Got to File->Build Settings...
and select Universal Windows Platform
.
On the right, change Build Type
to D3D
and select the SDK and Visual Studio Version.
SDK
and Visual Studio Version
must match (Don’t have warnings) to continue.
Click Build
and select the folder which you want Unity to build your project to.
Fix errors if your game have user data to save
If you use BinaryFormatter
, StreamWriter
or even UWP’s StorageFile
there will be errors.
You can try to use JsonUtility
and File
in UnityEngine
to access data files. Below is a short example.
public void SaveData()
{
string filePath = "data";
filePath = Application.persistentDataPath + "/" + filePath;
string jsonText = CustomEncryptFunc(JsonUtility.ToJson(GameData));
File.WriteAllBytes(filePath, Encoding.ASCII.GetBytes(jsonText));
}
private void LoadData()
{
string filePath = "data";
filePath = Application.persistentDataPath + "/" + filePath;
if (File.Exists(filePath))
{
string text = Encoding.ASCII.GetString(File.ReadAllBytes(filePath));
string jsonText = CustomDecryptFunc(text);
GameData = JsonUtility.FromJson<Data>(jsonText);
}
else
{
GameData = new Data();
SaveData();
}
}
C++/WinRT UWP project
After building the project, Unity will output a C++/WinRT UWP project.
C++/WinRT is neither C++/CLI nor Native C++.
An easy way to differentiate between them is to find
ref new
,gcnew
,new
respectively.
Building the UWP project
Open Package.appxmanifest
.
The icons and splashscreen can all be generated by a single icon.
Use 1024x1024 as the original logo size seems to work well.
I use UWPTileGenerator to generate icons, and use UWPVisualAssetsGenerator to generate splash screens.
Note that the splash screen images you use will be shown in the center of the window, so the image won’t extend to the entire view.
After you tested it in Debug
mode, search for your project name and uninstall it.
Pit falls
C3940 'EventRegistrationToken': identifier not found - possible mismatch between compiler and library versions. Please ensure vccorlib.h/.lib, vccorlib120.dll and c1xx.dll match
Change the Target Platform Version
Package.appxmanifest
cannot open in editor
If you can only open the Package.appxmanifest
in Xaml editor, you may not have the corresponding platform toolset installed. Change it in the project properties to solve the problem. (The project is not IL2CppOutputProject
or Unity Data
)
Fix errors if you have RockVR Unity plugin
RockVR uses some restricted APIs. So remember to remove it in the output UWP C++/WinRT project.
You can just delete Data\StreamingAssets
.
Sample error message:
API BitBlt in gdi32.dll is not supported for this application type. ffmpeg.exe calls this API.
Compile Errors
Consider changing Active Solution Platform
from ARM
to x86
. ARM
should also be removed when creating upload package.
Upload to Microsoft Store
Change the Debug
mode to Master
(Release
mode will produce some errors).
Menu: Project > Store > Create App Packages...
Follow the link: App submissions and it’s done!