Documentation
Ask or search…
K
Links

Quick Start

Tashi Network Transport for Unity
Before you start: Ensure that you have a newer version of Unity. The steps in this document were tested on version 2021.3.26f1.

Multiplayer packages

Install Netcode for GameObjects and Lobby in the Unity package manager.
Unity Package Manager with Netcode for GameObjects and Lobby packages installed

Install TNT for Unity

  1. 2.
    Install the SDK via Unity's Package Manager by:
    1. 1.
      Open Window > Package Manager
    2. 2.
      Press + and choose Add package from tarball...
    3. 3.
      Select the Tashi Network Transport file
    4. 4.
      Press Install
Tashi Network Transport installation

Configure multiplayer

Now that you've installed the appropriate Unity and Tashi packages, it's time to set up multiplayer and initialize a Tashi session.
First you want to create an object in your project that contains the NetworkManager component.
Next, you want to set the network transport in your NetworkManager configuration to TashiNetworkTransport:
Select TashiNetworkTransport as the Transport for NetworkManager
Now you define the Tashi Network Transport parameters:
Tashi Network Transport parameters
Tashi Consensus operates on the principle of all player clients knowing how to communicate directly with each other. To accomplish this, TNT exposes an Address Book which holds the communication routes for all players.

Initialize a session

Now that Tashi Network Transport for Unity has been installed and configured in the Unity IDE, you now have access to the necessary scripting classes that allow you to:
  • connect to a Lobby or game session initializer
  • pass around your player address book information
  • start a direct peer-to-peer leaderless gaming session
Below are code snippets from an example performing the steps to starting a Tashi gaming session using Unity's Lobby:

Import the TNT

using Tashi.NetworkTransport;

Instantiate the transport

private TashiNetworkTransport NetworkTransport => NetworkManager.Singleton.NetworkConfig.NetworkTransport as TashiNetworkTransport;

Get local data

private Dictionary<string, PlayerDataObject> GetPlayerData()
{
if (NetworkTransport.AddressBookEntry is null)
{
return new();
}
return new()
{
{
"AddressBookEntry",
new PlayerDataObject(PlayerDataObject.VisibilityOptions.Member, NetworkTransport.AddressBookEntry.Serialize())
}
};
}

Send local data

private async Task SendPlayerDataToLobby()
{
var options = new UpdatePlayerOptions
{
Data = GetPlayerData(),
};
Debug.Log($"Sending AddressBookEntry = {NetworkTransport.AddressBookEntry?.Serialize()}");
await LobbyService.Instance.UpdatePlayerAsync(_lobbyId, PlayerId, options);
}

Construct address book

private async Task ApplyPlayerDataFromLobby()
{
var lobby = await LobbyService.Instance.GetLobbyAsync(_lobbyId);
foreach (var player in lobby.Players)
{
if (player.Id == PlayerId || player.Data == null)
{
continue;
}
if (!player.Data.TryGetValue("AddressBookEntry", out var addressBookEntryData))
{
Debug.LogError($"Player {player.Id} didn't provide an AddressBookEntry");
continue;
}
Debug.Log($"Received AddressBookEntry = {addressBookEntryData.Value}");
var entry = AddressBookEntry.Deserialize(addressBookEntryData.Value);
if (entry == null)
{
continue;
}
NetworkTransport.AddAddressBookEntry(entry, player.Id == lobby.HostId);
}
ShowClientsConnected();
}
The Tashi Network Transport has now been initialized and is facilitating multiplayer gaming. You can configure all other multiplayer objects as you normally would.
Each player must have their own Profile ID for Unity Lobby to recognize multiple players.