Regions
Why use regions?
The greater the distance between a player and a game server, the more likely it is for packet delays to occur. Such delays can make a game unplayable. In extreme cases, players may not be able to connect to the game server at all.
To address this issue, Elympics hosts game servers in multiple regions around the world. Shorter distance from a player to the nearest server reduces latency and makes smooth, lag-free gameplay possible. This way, your game can be accessed from all over the globe.
Note that regions do not solve the problem of players being far away from each other. For a match taking place in a given region, all players within the match should be located close to that region to minimize their lag.
Keep in mind that players using different regions won't be matched together.
Available regions
Currently, the following regions are available for every game by default:
warsaw
(Poland),tokyo
(Japan),dallas
(Texas, USA),mumbai
(India).
Fallback region in case of providing null
, empty string or non-existent / not attached region is warsaw
.
If you want to host a game in a new region relatively far from the provided ones, please contact us using a form or simply at our Discord.
Usage in practice
To determine the closest region you can use the ElympicsCloudPing.ChooseClosestRegion
method.
It's recommended to cache the results in a runtime-persistent way so players don't have to wait unnecessarily for the region to be chosen in subsequent matchmaking attempts.
An example of such a caching mechanism is presented below:
public static class ClosestRegionFinder
{
private static (string Region, float LatencyMs)? CachedClosestRegion;
// Note that `ElympicsCloudPing.ChooseClosestRegion` is `async` and so it has to be handled with `await` in order to wait for its result.
// The same goes for every method wrapping this one, as we see below and in the next example.
public static async UniTask<(string Region, float LatencyMs)> GetClosestRegion()
{
if (!CachedClosestRegion.HasValue)
{
CachedClosestRegion = await ElympicsCloudPing.ChooseClosestRegion(ElympicsRegions.AllAvailableRegions);
}
return CachedClosestRegion.Value;
}
}
If you want to exclude your game from some regions or have any custom, private region connected, you should provide proper, modified collection of regions instead of ElympicsRegions.AllAvailableRegions
. It is recommended to use constants available in ElympicsRegions
class to avoid misspellings.
When to search for closest region
It may be tempting to search for the closest region just after the game loads (for example in Awake
),
but results from such method call will be unreliable because of huge computational overhead when first loading the game.
It's best to call ElympicsCloudPing.ChooseClosestRegion
reactively - just before the first authentication (and preferably only if the closest region has not yet been determined).
[UsedImplicitly]
public async void AuthenticateWithClosestRegion()
{
var (RegionName, LatencyMs) = await ClosestRegionFinder.ClosestRegion();
var authenticationAuthType = AuthType.ClientSecret;
await ElympicsLobbyClient.Instance.ConnectToElympicsAsync(new ConnectionData()
{
AuthType = authenticationAuthType,
Region = new RegionData(RegionName,false)
});
Debug.Log($"Authenticate in {Region} with ping {LatencyMs} as {authenticationAuthType}");
}
ElympicsLobbyClient.Instance.PlayInClosestRegion
method is not recommended as it pings each region every call.