Integrating the Microsoft Game Development Kit with your PC Unity game

This topic describes how to integrate the GDK with your Unity PC game.

Overview

The basic components for building a Unity game that appears in Microsoft Store or PC Game Pass are:

  • A Windows Standalone, x86_x64 Unity project
  • The runtime libraries that are provided in the GDK
  • The Unity package that's provided by Microsoft.

This unlocks access to Microsoft Gameplay Services such as Xbox achievements, leaderboards, cloud saves, Azure PlayFab Party chat, cross-platform multiplayer, and more.

Required software

The following tools and SDKs need to be installed to use Unity with the GDK:

GDK

  1. Ensure that you have access to these helpful resources. If you don't have access, contact your Microsoft representative.

  2. Download the GDK.

    Note: If you only need to publish to PC, you can download the GDK from GitHub.

    1. Go to Secure Xbox downloads.

    2. Select Game Core, and then select Confirm as shown in the following screenshot.

      Screenshot of the UI for selecting the file type

    3. Download the latest Tools and Recovery as shown in the following screenshot. Note that you don't need the Recovery if you are shipping only on PC.

      Screenshot of the UI for selecting the download versions of Tools and Recovery

    4. To download each, select Download Now.

  3. Install the GDK.

    1. Browse to where you downloaded the files. Extract each of the packages.

    2. Browse to the extracted GDK folder, find setup.exe, and then double-click it to open Setup.

    3. Complete the steps in the Setup pages.

Up to date Gaming Runtime Services (GRTS) and PC Bootstrapper

Starting with the May 2202 GRTS release, a PC Bootstrapper has been added to the PC game launch experience. The PC Bootstrapper has a dependency on the Gaming RunTime Service (GRTS) and If GRTS is out of date on your development PC, it can generate an error (E_FAIL) when attempting to sign in. See the PC Bootstrapper overview for more information.

Unity package

  1. Download the Unity package from GitHub.
    The package is in the Assets section of each release and will be named gdk-pc.[version number].unitypackage.

  2. Import the Unity package.

    1. Create a new Unity project. We recommend that you first go through this process with a new project before using it on your actual game.

    2. In the new Unity project, go to the main menu and select Assets > Import Package > Custom Package.

    3. In the file dialog that opened, select the GDK .unitypackage file you downloaded, and then click Open.

    4. If you see import errors on the console, select Clear. If the errors are no longer there, you can ignore them.

    5. Upon completion, the asset package is listed on the Project tab under the Assets folder as shown in the following screenshot.

      Screenshot of the UI for the package folder

    6. A new menu option, named GDK, now appears in the Unity main menu as shown in the following screenshot.

      Screenshot of the UI for the GDK option in the Unity main menu

  3. If you are developing for Xbox you will also need to install the Unity package for Xbox.

    1. Go to Unity private forums for Game Core. Go to a pinned post called Unity for Game Core Downloads, and then select that link.

    2. There are links to download packages. The GDK Package is already included in this package, so you don't need to download it. You might not need to download the other packages. To decide if you need to download them, read their descriptions.

You should now have everything you need to start integrating the GDK into your Unity game.

Testing your GDK and Unity package setup using the Hello World Unity sample

This section describes how to run the Hello World Unity sample.

  1. Select File > Open Scene and then open the sample scene under [Your project directory]\Assets\GDK-Tools\Examples\Sign-in\SignIn.unity.

  2. Open the Build Settings window in the Unity main menu by selecting File > Build Settings.

  3. Add the sample scene by selecting Add Open Scenes.

  4. Cancel the selection for any other scenes that you might have selected. This ensures that only the sample scene is selected: GDK-Tools/Examples/Sign-in/SignIn.

  5. Close the Build Settings dialog box.

  6. In the main menu, select GDK > PC > Build and Run.

  7. In the GDK - PC Build And Run dialog box, there should only be one sample scene listed: Assets/GDK-Tools/Examples/Sign-in/Basic.unity.

  8. Check Define MICROSOFT_GAME_CORE in the dialog box.

  9. Select Build and Run in the dialog box.

  10. When the sample game launches, if it prompts you to sign in to Xbox services, the GDK and Unity package are properly set up.
    Note that Unlock achievement won't yet work in the achievements sample scene.

You've built and run your first Unity game. Now you're ready to integrate the GDK into your own game.

Creating a product in Partner Center

Before you can test Xbox services functionality or publish a game to the Microsoft Store, you need to create your Xbox services-enabled product in Partner Center. For more information about Partner Center, see Setting up an app or game in Partner Center, for Managed Partners.

Associate your game with Microsoft Store

For your game to be able to access Xbox services, you need to its game configuration to match the values for the Partner Center project you created in the last step.

  1. Open the Microsoft Game Configuration Editor, by going to Unity; in the top-level menu, select GDK > Associate with the Microsoft Store as shown in the following screenshot.

    Screenshot of the UI for Associate with the Microsoft Store menu option

  2. In the window that opened, select Associate with the Store as shown in the following screenshot.

    Screenshot of the UI for Associate with the Store

  3. In the window that opened, follow the steps listed in the wizard.

  4. Enter the rest of the required information with the values from your Partner Center project.

    • The Publisher field is necessary. You can find the value in Partner Center under the Package/Identity/Publisher row.
    • The Tile Image field can be left with the default image.
    • Selecting the PC tab allows you to specify any additional features like multiplayer protocol, custom installers, or framework dependencies.
  5. Click Save.

Creating a test account

You'll need to create a test account with access to your development sandbox to be able to test Xbox services functionality. For information about creating test accounts, see Creating test accounts.

Downloading the Xbox App

The Xbox app is helpful for verifying that your test account is signed in. You can download it here: Xbox App

Switching to your development sandbox

After you've created a test account, you can use the account to access your development sandbox by using the following steps.

  1. To find your sandbox ID, go to Partner Center.

  2. Navigate to your game.

  3. Select Xbox services > Gameplay settings in the left navigation pane.

    Note

    Your sandbox ID is on the first tab in the upper-left corner of the Gameplay Setting page. It's named something like "ABCDEF.0".

  4. In Unity, open the Sandbox Switcher by going to GDK > PC > Switch Sandbox.

  5. Your sandbox is automatically populated in the sandbox drop-down list as shown in the following screenshot.

    Screenshot of the UI for Switch Sandbox

  6. Select the Switch Sandbox button.

  7. To verify that you successfully switched your sandbox, select Launch Apps to reopen the Microsoft Store app, Xbox app, and Xbox Console Companion.

  8. Sign in to the Xbox App with the username and password from the Xbox test account that you created earlier. Verify that you can sign in.

To switch back to RETAIL mode from your development sandbox

  1. In Unity, go to GDK > PC > Switch Sandbox.

  2. Select Retail from the sandbox drop-down list.

  3. Select the Switch Sandbox button.

  4. Select Launch Apps.

  5. Open one of the apps. Try to sign in with a non-test account, and then verify that you can sign in.

Adding Xbox services to your game

This section describes how to add Xbox services sign-in, cloud saves, achievements, and commerce to your game.

Building and Running your game with Xbox services enabled

Prior to 2207 GDK Unity Package

Prior to the 2207 GDK Unity Package, in order to run your game with Xbox services enabled you had to run your game using the GDK Build and Run command (GDK > PC > Build and Run).

2207 GDK Unity Package

As of the 2207 GDK Unity Package, you can run your game through the standard Unity Build and Run command (File > Build and Run), and through the GDK Build and Run command (GDK > PC > Build and Run) if you're using the March 2022 GDK Update 1 or June 2022 GDK or later.
In addition Xbox services can be enabled when running within the editor.

To enable playing within the editor, use GDK > PC > Update Editor Game Config after you've associated your project with a Microsoft Store app (or each time you make any changes to your MicrosoftGame.Config). It will give a permissions prompt and then copy your MicrosofGame.Config to the editor's executable location. Then, enable Define MICROSOFT_GAME_CORE in the GDK > PC > Build and Run menu. From then on, you'll be able to test within the editor.

Sign-in

To implement sign-in in Unity you need to add the GdkHelper prefab into your scene.
In Unity, in the Project window, go to \Assets\GDK-Tools\Prefabs\GdkHelper.prefab, and then drag the GdkHelper prefab into your scene.

To test your new functionality, switch to your development sandbox using the steps in the Switching to your development sandbox section above and then build and run your game by selecting GDK > PC > Build and Run.
If you have trouble getting sign-in to work, refer to the Troubleshooting sign-in and sandboxes article for help.

Cloud saves

To add cloud save functionality to your game you'll need to use the GDK.Helpers.Save and GDK.Helpers.LoadSaveData functions.
For an example of integrating cloud save, review the sample code in the Project window under Assets\GDK-Tools\Examples\Cloud Saves\GameSaveSampleLogic.cs.

To test your new functionality, switch to your development sandbox using the steps in the Switching to your development sandbox section above and then build and run your game by selecting GDK > PC > Build and Run.

Achievements

To add support for achievements to your game, you'll need to use the GDK.Hellpers.UnlockAchievement function.
For an example of integrating achievement unlocking, review the sample code in the Project window under Assets\GDK-Tools\Examples\Achievements\UnlockAchievementSampleLogic.cs

In addition to adding support for achievements in your game, you'll need to enable publishing achievements and create your achievements in Partner Center as described in the following sections.

To enable publishing achievements in Partner Center

  1. Ensure that you have sign-in working before implementing achievements.

  2. Go to Partner Center.

  3. On the left pane, select Xbox Settings as shown in the following screenshot.

    Screenshot of the UI for Xbox Settings

  4. Under Publish Achievements to Retail?, select Yes I will be publishing achievements as shown in the following screenshot.

    Screenshot of the UI for Yes I will be publishing achievements

To publish a new achievement in Partner Center

  1. Select Gameplay settings under the Xbox services section on the left pane as shown in the following screenshot.

    Screenshot of the UI for Gameplay settings

  2. To go to the Achievements page, select the Achievements link.

  3. Select New achievement. Enter the required information.

  4. When the new achievement is created, take note of the achievement's ID in the ID field. It's autogenerated and will be a string like "1".

  5. To open the Publish gameplay settings dialog box, select Publish.

  6. Change the To: field to your developer sandbox that you created earlier. Select Confirm.

  7. Wait for the publishing process to be completed.

To test your new functionality, switch to your development sandbox using the steps in the Switching to your development sandbox section above and then build and run your game by selecting GDK > Build And Run.

Adding commerce to your game

To make purchases in your game, you'll use the GDK.Helpers.ShowPurchaseUIAsync and Gdk.Helpers.GetAssociatedProductsAsync functions. For an example of an in-game store implementation, look at the In Game Store example in the Project window under Assets\GDK-Tools\Examples\In Game Store.

Once you've added commerce support to your game, you'll need to create add-ons for purchase and prepare your game for testing commerce by following the steps in Creating add-ons for your game and Preparing for testing commerce.

Creating add-ons for your game

This section shows you how to create listings for your in-game items in Partner Center.

  1. Go to Partner Center.

  2. Navigate to your game.

  3. In the navigation pane on the left, select Add-ons.

  4. Click the Create a new... button at the top. Select the appropriate category

  5. Fill out the required information and create any additional in-game items you need.

  6. Click on the add-on in the table to see its details.

  7. In the left navigation, select the Durable setup page (or Consumable setup if you created a consumable).

  8. Click the Show details button in the Identity Details section.

  9. Copy the value of the Store ID field. This value will be passed to the ShowPurchaseUIAsync API later in this section.

  10. Fill in the rest of the required fields. Set the price to free for easier testing.

  11. When you are finished, publish to your developer sandbox.

Testing your commerce functionality

This section shows you how to prepare your environment for testing store APIs. See Enabling XStore development and testing for more details.
In order to test your commerce functionality, you will have to have first uploaded the package for your game to Partner Center as described in the Publishing on Partner Center section (you will need to select a development sandbox to upload to instead of RETAIL).

  1. Switch to your development sandbox using the steps in the Switching to your development sandbox section above.

  2. Search for your game in the Xbox App.

  3. Download and install your game. This is an important step because it will give your test account a license to the game. Without a license, you will get an E_IAP_UNEXPECTED error.

  4. For console, you can get the value of the Content ID and EKB ID by running xbapp list /d in the Gaming Command Prompt.

  5. For PC, you can get the value of the Content ID by opening a command prompt and type: reg query HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Store\ContentId

  6. Find the Content ID value for your game package.

  7. Go to \GDK-Tools\ProjectMetadata and open the MicrosoftGame.config file. Note: You cannot open it in Unity. Instead, you will need to browse to the folder in the file explorer and open it in another program.

  8. Replace the ContentIdOverride value with the value obtained above. For console, you will also need to set an EKBIDOverride. But note that the MicrosoftGame.config values for console are set in a different location than PC. For Xbox, they can be found under Player Settings... > Publishing Settings for the Xbox build platform.

See Also

Enabling XStore development and testing Troubleshooting store integration Troubleshooting sign-in and sandboxes

Additional considerations before shipping

Checking for mandatory updates

Checking for mandatory updates happens automatically, without you having to write code, on the console, and through the PC Bootstrapper on the PC.

Certification test cases

Before you ship it is a good idea to look through the policies and Xbox requirements.

Unity considerations with TCUI dialogs

It is recommended that "Application.runInBackground" is set to true for any game that expects to display a title-callable UI (TCUI) dialog. See Window display modes and title-callable UI dialogs for additional information on successfully showing TCUI dialogs.

Publishing on Partner Center

This section describes how to package, upload, and publish your game on Partner Center.

  1. In Unity, go to GDK > PC > Build and Run.

  2. Select the Create package to upload to the store check box as shown in the following screenshot.

    Screenshot of the UI for creating a package to upload to Microsoft Store

  3. Select Build.

  4. When prompted, choose a folder for the build package files.

  5. When the build finishes, it opens the folder that contains the files you need to upload to Microsoft Store.

  6. Go to Partner Center

  7. Select Packages on the pane as shown in the following screenshot.

    Screenshot of the UI for Packages

  8. Upload the .msixvc, .ekb, and .xml files from step 5 in this section by dragging the files to the drag area as shown in the following screenshot. If you can't upload an .msixvc file, contact your Microsoft representative for help.

    Screenshot of the UI for uploading files

  9. Enter the required information in the Properties, Age ratings, Store listings, and Pricing and availability sections as shown in the following screenshot.

    Screenshot of the UI for the Properties, Age ratings, Store listings, and Pricing and availability sections

  10. On the Store listings page, ensure that you upload a trailer. Trailers aren't listed as mandatory in the UI but are required for games.

  11. To publish, select Review and publish as shown in the following screenshot.

    Screenshot of the UI for Review and publish in Partner Center

  12. Select RETAIL. This submits your game to certification.

    Note

    If you see errors about revenue SKUs, they're created as part of the certification process. To publish your packages to retail, you must go through certification.

  13. After your game passes certification, it can be released to retail. You can see when your game has passed certification on the Game Overview page, under the Publishing Status section.

See Also

Troubleshooting sign-in and sandboxes