Skip to main content

Steam

This guide explains how to configure Steam payments for use in UniPay, viable on Standalone platforms running the Steam Client (Windows or Mac).

Prerequisites

You will need to register for a Steamworks developer account, where you are able to publish your game to the Steam ecosystem.

In order to publish your game in Steam, you will have to pay the "Steam Direct Fee" for creating an unique AppID that acts as an identifier for your game. Note that the application you create in Steamworks needs to be of type Game, otherwise the in-game overlay popup for authorizing payments will not show up!

Steam-Native010

For associating purchases with the player's Steam account and storing them in the player's inventory, UniPay makes use of the Steam Inventory Service. If you would like to read more about it, please see this link. In Steamworks, go to Dashboard > Your App > Edit Steamworks Settings > Community > Inventory Service and enable the checkbox.

Steam-Native020

Create Web API Key

In order to initiate Steam purchases via the Steam Web Store and display the purchase overlay in-game, you have to assign a Web API Key to your Steam Economy settings.

Create a Publisher Web API Key for your app group. Here is the official documentation on what Web API Keys are for. Under User & Permissions > Manage Groups you should already have a group named Everyone (WebAPI). Open the Group and make sure that:

  1. Your user is a member of the group with Admin permissions
  2. Your app and package is assigned to this group. The package ID can be found by navigating to Apps & Packages > View Packages
  3. On the right side, after clicking on "Create WebAPI Key" it is displayed below

Steam-Native030

Steam-Native040

Next, navigate to Dashboard > Your App > Edit Steamworks Settings > Community > Economy and insert the newly created Web API Key into the Asset Server Key field. Afterwards, press Save.

Steam-Native050

You will receive a notification about unpublished configuration changes, so follow the link to publish them. Do not worry, your app will not be released to the store by doing this.

Steam-Native060

Importing Steam SDK in Unity

As a third-party Steam SDK, Steamworks.NET is a reliable solution. Head over to its installation page and download & import its latest unitypackage file (from GitHub releases).

  • As written in the SDK's "Unity Instructions", open the steam_appid.txt in your project's root folder and replace the number with your own Steam App ID
  • In the SteamManager script on line 99, replace AppId_t.Invalid with your own Steam App ID
  • Restart Unity

Next, add the SteamManager script to a new empty game object named SteamManager in your first scene. This script is responsible for establishing a connection between your game binaries and the Steam network on launch.

Steam-Native070

Optional: while you're at it, you could add an #IF STEAM_IAP define at the very top of the SteamManager script (and an #endif at the last line), so that it only compiles for the standalone platform, when Steam has been chosen in UniPay's Project Settings.

Lastly, open UniPay's Project Settings and set Standalone = Steam.

Steam-Native080

Create in-app purchases

For a summary and best practices for using Steam Microtransactions, please refer to Steam's documentation. First we have to define what products we would like to sell. In Steamworks, go to Dashboard > Your App > Edit Steamworks Settings > Community > Inventory Service. Scroll down to the bottom to find a list of Item Definitions. An example of a JSON product schema can be found in Steam's Inventory Schema Documentation, or directly by going here.

Steam-Native090

Below is an example of a valid JSON product schema:

  • replace the App ID with your own
  • it is recommended to start with an itemdefid (product ID) of 100 and increment by 100 for each product
{
"appid": "<YOURAPPID>",
"items": [
{
"itemdefid": "100",
"type": "item",
"name": "My Item 1",
"price": "1;VLV500",
"description": "My Item 1"
},
{
"itemdefid": "200",
"type": "item",
"name": "My Item 2",
"price": "1;VLV1000",
"description": "My Item 2"
}
]}

After uploading your JSON, the list of Item Definitions should be populated. In Unity, open Edit > Project Settings > UniPay In-App Purchasing and define your IAPs there too. Since product IDs are usually alphanumeric on all stores except Steam, where product IDs are numerical only, you might want to use UniPay's Product Overrides feature for them.

PSteam-Native100

Testing payments

Testing Steam payments requires the Steam Overlay to show up (where you are able to authorize in-app purchase transactions). The Steam Overlay visibility can be a bit inconsistent at times, especially if you are launching your game right within Unity - mostly this will not work. Because of that, it is recommended to just Build - not Build & Run your game with Unity. After you've created the build, move it to your \Steam\steamapps\common\<game folder> Steam games directory.

Log into the Steam Client with your Steamworks developer account. Press ADD A GAME > Add a Non-Steam Game and link the game executable.

PSteam-Native110

Then, run it from within Steam - the Steam Overlay should show up at launch, as expected. To verify this, press Shift-Tab.

Steam-Native120

Trying to buy a product should then invoke the native Steam Overlay with the purchase dialog.

Steam-Native130

If you are making a new test build later, make sure to replace the existing executable in that steamapps directory directly (so that you don't have to re-link it) and launch it from Steam as before.

Unsolved Errors

If you can’t see any products or if the Steam purchase Overlay does not show up at all, you may have some issues with your Unity/Steamworks settings and/or errors on the device.

As a summary, please verify that all of the following points have been met:

  • your Steamworks app is of type "Game" (not Application since that does not support the overlay)
  • in Steamworks, you've created a Web API Key
  • in Steamworks, your app and package was added to the group with that Web API Key
  • the steam_appid.txt file in your project's root folder contains the correct app ID
  • you have uploaded Items to the Steam Inventory Service using a JSON file (with the correct app ID)
  • in-app product identifiers in the UniPay In-App Purchasing Project Settings matches the ItemDefIds added in Steamworks
  • Standalone billing selection in the UniPay In-App Purchasing Project Settings is set to "Steam"
  • you have placed the SteamManager script into your first game scene and start it from there
  • you have deployed the files at your Steam app location under "\Steam\steamapps\common< game folder >"
  • you are logged in with your developer account when launching the Steam app
  • you have added the game to and starting from Steam (not Play Mode in Unity editor)
  • if the Steam Overlay (Shift-Tab) still does not open, recheck all app IDs entries!

Check that the following URL opens correctly when replaced with your app ID and itemDef ID: https://store.steampowered.com/buyitem/appid/itemid/

In cases of the Steam Overlay opening, but the purchase overlay does not:

  • if your game's name in the top right corner of the Steam Overlay is not displayed, there is an issue with the Steam connection
  • try uploading your game to Steam as a build and then downloading from within the Steam app
info

Please note that in case of issues with this process, I am not able to guess or remotely debug the exact cause for you. Since a major part of this guide is not written for UniPay in particular, there is a high chance that your issue has been experienced by many, many other developers before and is covered somewhere already - debug your device, do a Google search for the error message and look out for popular Steamworks developer threads!

tip

If you need help with the app setup, testing process or solving issues with your app's connection to Steam, I am providing extended support for this via PREMIUM support. Contact me on the Unity Forum or on Discord to discuss your requirements.

Please add me to your Steamworks partner account so I am able to verify all points above and do a test build. Navigate to Users & Permissions > Manage Users > Invite User:

Steam-Native140

Explanation of required permissions:

  • Manage Users: view and edit the Web API Key
  • Edit App Metadata: view and edit Inventory and Economy settings
  • Publish App Changes To Steam: publish changes in above categories

After the invite and my acceptance, you will receive an additional email notification to approve my user.