Key concepts

Before you start, take a few minutes to understand some of the key concepts that underpin Unity Gaming Services.

Server-side game systems

For live games, especially multiplayer ones, it’s important to have a single place to manage player data. Rather than each player’s device managing that player’s data, a central server communicating with all player devices handles important game decisions. This can help mitigate cheating tactics that may allow players to gain an unfair advantage, or acquire resources that they would otherwise need to purchase or earn. Similarly, to ensure that live events and competitive features are fair to all players, your game should manage data and decisions in the cloud.

Unity Gaming Services lets you:

  • Keep player data safely in the cloud using the Cloud Save service.
  • Run economy and game logic in the cloud using the Economy and Cloud Code services.

Asynchronous code

Like any online service, Unity Gaming Services are all based on asynchronous operations. This means that client requests to a service don’t stop the game to wait for the response. Gameplay, UI, and animations can continue while service requests occur in the background.

For this, Unity Gaming Services rely on the Task-based Asynchronous Pattern (TAP), which makes writing asynchronous code in C# relatively easy. If you’re already familiar with writing code in Unity, you probably understand Coroutines, which you can use for asynchronous logic. While Coroutines are still useful for controlling what’s going on in the foreground, async Tasks are better for managing things happening in the background, such as web requests.

Throughout the UGS documentation, you will encounter the async and await keywords. An async method returns a Task that represents an ongoing process. The await keyword tells the caller to wait until the called async method has finished before continuing.

For example, to update a player’s currency data, you might have something like the following code:

async Task RefreshPlayerWallet()
{
	// Use an animation to show the player something is happening.
	waitIndicator.gameObject.SetActive(true);

	// Download this player's currency statuses from UGS;
	// this asynchronous task won't interrupt the animation.
	var newWalletData = await EconomyManager.RefreshWalletData();

	// Once you have the downloaded data, update your UI.
	walletView.Refresh(newWalletData);

	waitIndicator.gameObject.SetActive(false);
}

For more information, see Microsoft’s conceptual guide on asynchronous programming.

SDK APIs versus REST APIs

There are two ways to access Unity Gaming Services programmatically:

  • SDK (client) APIs
  • REST (web) APIs

Client APIs

If you intend to use Unity Gaming Services with the Unity game engine, Unity recommends using client APIs for your project.

Client APIs make it easier to access Unity Gaming Services APIs from a supported language (C#) within the context of the Unity Editor. Unity developers can access all of the services’ functionality with Unity packages. These SDKs install directly to your Unity project and provide all the C# API libraries you need. Client APIs simplify your workflow and significantly reduce the amount of code you need to write.

Web APIs

Non-made with Unity developers can access Unity Gaming Services APIs via web endpoints, or REST APIs. REST APIs provide more flexibility and allow you to automate your workflows by using your favorite language and gaming engine.

Onboarding impact

Whether you’re using the SDK or REST APIs, you need to create a project on the Unity Cloud Dashboard. However, if you’re using the REST APIs, the subsequent steps in the getting started guide may differ slightly. Unity recommends that these customers visit the services API documentation website for onboarding.