A Netick integration for Unity Transport and Unity Relay, featuring multi-protocol support and cross-platform connectivity. This package enables players from WebGL, mobile, and native platforms to connect to the same server instance using UDP, WebSocket, or Unity's Relay service.
- Multiple Protocol Support: UDP, WebSocket (TCP), Relay UDP, and Relay WebSocket
- Cross-Platform Connectivity: Simultaneous protocol hosting for WebGL and native clients
- Unity Relay Integration: Built-in support for Unity's Relay service for NAT traversal
- Secure Connections: Optional TLS (WebSocket) and DTLS (UDP) encryption
This package requires Netick 2 and can be installed via Unity Package Manager using Git URLs.
Dependencies:
All dependencies can be installed via Unity Package Manager using Git URLs. For detailed instructions on installing packages from Git repositories, see the Unity documentation on installing from a Git URL.
Quick Installation Steps:
- Open Unity Package Manager (Window > Package Manager)
- Click the + button in the top-left corner
- Select Add package from git URL...
- Add the following packages in order:
- First, add Netick:
https://github.com/NetickNetworking/NetickForUnity - Then, add this package:
https://github.com/karrarrahim/UnityTransport-Netick.git
- First, add Netick:
- Click Add for each package
After installation, create a transport provider instance:
- In Unity, right-click in the Project window
- Navigate to Create > Netick > Transport > UnityTransportProvider
- Name the asset (e.g., "UnityTransportProvider")
- Configure transport settings in the Inspector
The transport supports four distinct protocol types:
- UDP: Standard User Datagram Protocol for low-latency connections
- WebSocket (TCP): TCP-based protocol for WebGL compatibility
- Relay UDP: Unity Relay service using UDP transport
- Relay WebSocket: Unity Relay service using WebSocket transport
The transport can simultaneously host multiple protocols on a single server instance, enabling cross-platform connectivity between WebGL clients and native applications.
Port Allocation Logic:
When multiple protocols are enabled, ports are automatically allocated sequentially:
firstProtocol = 7777
secondProtocol = 7777 + 1
thirdProtocol = 7777 + 2
Example Configuration:
- UDP listens on port 7777
- WebSocket listens on port 7778
- Relay UDP listens on port 7779
This automatic allocation ensures no port conflicts when running multiple protocols simultaneously.
Optional encryption can be enabled for enhanced security:
- WebSocket Secure (TLS): Encrypted WebSocket connections
- Secure UDP (DTLS): Encrypted UDP connections using Datagram Transport Layer Security
Note: Secure connections require additional configuration and certificate management. Refer to Unity's networking documentation for certificate setup procedures.
Unity Relay provides NAT traversal and relay services, enabling players behind restrictive firewalls to connect. The transport includes built-in Relay support through Unity's Multiplayer Services SDK.
Installing Multiplayer Services Package:
- In the Unity Editor, open Window > Package Manager
- Select Unity Registry from the dropdown
- Search for
Multiplayer Services(orcom.unity.services.multiplayer) - Click Install
Note: The older Relay SDK has been deprecated. Use the Multiplayer Services package instead.
Scripting Define Symbol:
After installing the package, add MULTIPLAYER_SERVICES_SDK_INSTALLED to your project's scripting define symbols:
- Navigate to Edit > Project Settings > Player
- Expand Other Settings
- Add
MULTIPLAYER_SERVICES_SDK_INSTALLEDto Scripting Define Symbols
Configure the transport to use Relay services:
- Select your UnityTransportProvider asset
- In the Inspector, set Server Protocol to either:
- Relay UDP: For Relay-based UDP connections
- Relay WebSocket: For Relay-based WebSocket connections
Before launching Netick as a host, initialize the Relay allocation:
using Unity.Services.Relay;
using Unity.Services.Relay.Models;
public async void StartHost()
{
int maxPlayers = 10;
// Create relay allocation
Allocation hostAllocation = await RelayService.Instance.CreateAllocationAsync(maxPlayers);
NetickUnityTransport.SetAllocation(hostAllocation);
// Generate join code for clients
string joinCode = await RelayService.Instance.GetJoinCodeAsync(hostAllocation.AllocationId);
// Display or share the join code with clients
Debug.Log($"Join Code: {joinCode}");
// Start Netick as host
Network.StartAsHost(transportRelay, 0, sandboxPrefab);
}Workflow:
- Create a Relay allocation specifying maximum player capacity
- Provide the allocation to the transport via
SetAllocation() - Generate a join code from the allocation ID
- Share the join code with clients through your lobby system or UI
- Initialize Netick as host
Clients use the host's join code to establish Relay connections:
using Unity.Services.Relay;
using Unity.Services.Relay.Models;
public async void JoinHost(string joinCode)
{
// Join relay allocation using host's code
JoinAllocation playerAllocation = await RelayService.Instance.JoinAllocationAsync(joinCode);
NetickUnityTransport.SetJoinAllocation(playerAllocation);
// Start Netick as client
NetworkSandbox sandbox = Network.StartAsClient(transportRelay, 0, sandboxPrefab);
// Connect to host (address parameter ignored when using Relay)
sandbox.Connect(0, "0.0.0.0");
}Workflow:
- Obtain the host's join code (from lobby, UI input, or matchmaking)
- Call
JoinAllocationAsync()with the join code - Provide the join allocation to the transport via
SetJoinAllocation() - Initialize Netick as client
- Call
Connect()(the address parameter is unused with Relay)
Important: When using Relay, the address parameter in Connect() is ignored. Connection routing is handled automatically through the Relay service using the join allocation.
The NetworkConnectionRequest data buffer (byte[]) has a fixed size of 200 bytes to avoid garbage collection at runtime.
Usage Considerations:
public override void OnConnectRequest(NetworkSandbox sandbox, NetworkConnectionRequest request)
{
// Use request.DataLength to determine actual data size
int actualDataLength = request.DataLength;
// Process only the relevant portion of the data
byte[] relevantData = new byte[actualDataLength];
Array.Copy(request.Data, relevantData, actualDataLength);
// Or manually resize the array for your use case
// byte[] customData = new byte[actualDataLength];
// Buffer.BlockCopy(request.Data, 0, customData, 0, actualDataLength);
}- Best for: Native platforms with low-latency requirements
- Use cases: Fast-paced action games, competitive multiplayer
- Considerations: May be blocked by restrictive firewalls
- Best for: WebGL builds and browser-based games
- Use cases: Cross-platform games requiring browser support
- Considerations: Slightly higher latency than UDP due to TCP overhead
- Best for: Games requiring NAT traversal and global connectivity
- Use cases: Public matchmaking, mobile games, games with players behind restrictive NATs
- Considerations: Introduces additional latency through relay servers; subject to Unity Relay service limits
- Best for: Games supporting both WebGL and native clients
- Use cases: Cross-platform multiplayer games
- Implementation: Enable both UDP and WebSocket protocols on the server
For Netick-related questions: Netick Discord Server
For Unity Transport Documentation: UTP Documentation
For Unity Relay documentation: Unity Relay Services