Appearance
Appearance
When running the game in the Unity Editor, you can find the connection simulation tool in the inspector of the MetaplaySDKBehavior
component. Depending on the configuration, you can place the GameObject containing this component into the scene or it will be automatically injected by the SDK. If the component is automatically injected, it will be in a MetaplaySDKBehavior
GameObject. This tool requires an actual network connection and will not work in offline mode.
When the game is running, the tool shows two pieces of information about the client's internal connection state:
Connection.IsHealthy
.The tool also allows you to set the Quality simulation value for the connection. The following modes are available:
Spotty network updated
prefix.Note that the mode can be switched at runtime and this often is required for some test cases.
In addition, you can also use the tool to simulate latency by toggling the Enable Latency Simulation
option while the game is not running. While latency simulation is enabled, you can freely change the added latency through the MetaplaySDKBehaviour
component. Latency simulation is also available in builds; however, there is no readily available built-in UI to enable or change latency.
If you wish to enable latency simulation manually through code (to, for example, toggle it in a build), you can do so by adding a lambda that creates LatencyMessageMessageTransport
to MetaplayClient.Connection.CreateTransportHooks
before MetaplayClient.Connect()
is called.
// Initialize Metaplay SDK.
MetaplayClient.Initialize(new MetaplayClientOptions { ... });
// You can use this instance later to modify the amount of added latency.
LatencySimulationMessageTransport latencySimulationMessageTransport;
// Add a lambda that wraps the internal MessageTransport with the LatencySimulationMessageTransport.
MetaplayClient.Connection.CreateTransportHooks.Add(createInnerTransport => serverGateway =>
{
latencySimulationMessageTransport = new LatencySimulationMessageTransport(createInnerTransport(serverGateway));
return latencySimulationMessageTransport;
});
MetaplayClient.Connect();
The tool can be used to test several different network scenarios, here are a few:
This simulates dropping from WiFi without backup connection being available.
Connection.IsHealthy
becomes Unhealthy.Error
(or Connecting
is game automatically reconnects).This simulates walking on the fringe of a WiFi range, where no data gets delivered, but the device still claims to have a working connection.
Launch game in Perfect link mode.
Connection.IsHealthy
becomes Unhealthy.Error
(or Connecting
is game automatically reconnects).This simulates temporary loss of network and recovery. This is expected to be transparent (with the exception of showing a connectivity warning).
Connection.IsHealthy
becomes Unhealthy.Alternatively, you can just leave the connectivity mode set to Spotty link and test the game normally. Note that the spottiness of Spotty link is random, and it might sometimes generate connectivity losses longer than the Game's maximum limit. This is intentional, as it allows for convenient testing of a range of different scenarios without additional effort.
If you determine that the game is functioning as desired, but the default time limits in Metaplay SDK are unsuitable, you can change them. The connectivity rules and settings are defined in the following places:
Connection.Config
in MetaplayConnection
defines client-side limits for a single connection. These default values can be overwritten after MetaplaySDK.Start
and before Connection.Connect()
. This can for example be used to make the connectivity warning appear faster (if your game requires better network connections) or slower (if you tolerate a worse connection).PlayerOptions.ClientTimeMaxBehind
and PlayerOptions.ClientTimeMaxAhead
determines the temporal tolerances that the client must stay within. In practice, ClientTimeMaxBehind
determines the maximum non-connectivity period.SessionActor.ShutdownPolicy
determines the session linger time, i.e. the time that is still possible to transparently restore a session after a connection loss. Note that the linger timer starts when a connectivity loss is observed by the server. This is generally unobservable to the client - there is no guarantee the client has or will observe the connectivity loss in a timely fashion.