Build an application with the Microsoft GDK API package
Understand how to use the GDK API package to build a project for the Windows platform.
Note
The GDK API package does not create or manage the MicrosoftGame.config file. Consider using the Microsoft GDK Tools package (com.unity.microsoft.gdk.tools) to make best use of the GDK API package for an improved workflow.
Set up and build a project using the GDK API package
To set up and build a project using the GDK API package, complete the following tasks:
- Import a sample
- Include the sample scene in the build
- Add the Microsoft Game Configuration file
- Run the project
Import a sample
The GDK API package provides some samples for you to explore the Microsoft Xbox services services. Use the following steps to import one of the samples:
- Create a new Unity Project.
- In the main menu, go to Window > Package Manager.
- In the packages list view, select the Microsoft GDK API package.
- In the Package details view, select Samples.
- Locate the Sign-in sample and select Import. Unity imports the selected package sample into
Assets/Samples/Microsoft GDK API/<package version>/Sign-in
. - Double click the SignIn scene asset to load the sample scene.
Include the sample scene in the build
- In the main menu, go to File > Build Settings and select the Windows platform.
- Add the sample scene by selecting Add Open Scenes.
- Select Build to create a player in your target folder. Don’t use Build & Run as the
XGameRuntime
will fail to initialize due to a missingMicrosoftGame.config
.
Note
If using Unity version 2023.3, Build Settings are now part of Build Profiles.
Add the Microsoft Game Configuration file
Your project must contain a valid Microsoft game configuration file for your game to run. The GDK API package itself doesn’t provide you tools to create or maintain this file.
- In the Project window, navigate to
Assets/Samples/Microsoft GDK API/<package version>/Sign-in/MicrosoftGameConfig
. - Copy the
GdkSignInSample.mgc
to the resulting build folder where the built player is located. You can locate the Microsoft Game Config file using the right-click menu option, Show in Explorer. - Rename the file copied in the earlier step to
MicrosoftGame.config
.
For more information about the MicrosoftGame.cofig file, refer to MicrosoftGame.config.
Note
For the best experience it’s recommended to use the Microsoft GDK Tools package. This package makes working with Microsoft Game Configuration files easier, as you don’t need to maintain this file manually during the build process.
Run the project
At this point you can either run the built application executable directly from the output folder or within the Unity Editor using the Build And Run option with the same output location. Don’t clean the build folder on build, or the MicrosoftGame.config file will be removed.
Build a sample using the Microsoft GDK Tools package
Using both the Microsoft GDK API and Microsoft GDK Tools packages together is the recommended approach when developing for GDK. The GDK Tools package provides support that you don't get with the standalone GDK API package.
To build and run a sample using the Microsoft GDK Tools package, use the following steps:
- Follow the previous steps to:
- Install the Microsoft GDK Tools package.
- In the Project window, navigate to
Assets/Samples/Microsoft GDK API/<package version>/Sign-in/
. - Double click on the
GDKSignInSample.gdksettings.asset
to activate it. - In the main menu, go to File > Build Settings and select the Windows platform.
- Ensure the sample scene is still selected in the Scenes In Build section.
- Select Build And Run. The GDK Tools package will automatically create the MicrosoftGame.config based on the GDK Settings provided by
GDKSignInSample.gdksettings.asset
.
MicrosoftGame.config
Consider the following important points relating to the MicrosoftGame.Config
file:
- Your project must include a valid
MicrosoftGame.Config
file for the correct initialization of the GDK API at runtime. - The
MicrosoftGame.Config
file must be included in the same folder as the executable that initializes the GDK API. The executable can be a built game executable or Unity.exe if you’re using the built-in Player of Unity Editor. In case of built game executable, make sure to save theMicrosoftGame.Config
file in the same folder as your project build. - The
MicrosoftGame.Config
file must be correctly configured, with valid settings for elements such as TitleID and MSAAppId. For more information, refer to MicrosoftGame.config overview. - Pass the correct SCID in the call to
SDK.XBL.XblInitialize()
. - If your project doesn't include a
MicrosoftGame.Config file
, you will get the error0x87E5001F (E_GAME_MISSING_GAME_CONFIG)
.