Multiplayer API Logo

Multiplayer API

Unity SDK for
Multiplayer Games

JsonUtility-compatible SDK designed specifically for Unity developers. Full serialization support, coroutines, and seamless integration with your Unity projects.

Unity-Specific Features

Built with Unity developers in mind

JsonUtility Ready

Full compatibility with Unity's JsonUtility serialization system. No reflection or complex JSON handling needed.

Coroutine Based

Uses Unity coroutines for async operations, perfect for game loops and frame-based updates.

IL2CPP Safe

Arrays instead of Lists, no reflection, and IL2CPP-compatible serialization for mobile builds.

Unity SDK

Complete JsonUtility-compatible SDK for Unity developers

Unity SDK Download

Complete JsonUtility-compatible SDK designed specifically for Unity developers. Includes comprehensive multiplayer functionality with coroutines, authentication, and proper serialization for mobile builds.

JsonUtility Ready

Full compatibility with Unity's JsonUtility serialization system

Coroutine Based

Uses Unity coroutines for async operations and game loops

IL2CPP Safe

Arrays instead of Lists, no reflection for mobile builds

Multiplayer Ready

Complete player management and matchmaking system

Game Rooms

Real-time room management with actions and updates

Leaderboards

Competitive rankings and player statistics

View on GitHub
Full Repository
Quick Installation Guide
1
Download & Add SDK
  1. Click "Download Unity SDK" button
  2. Save SDK.cs
  3. In Unity: Assets → Import New Asset
  4. Select the downloaded SDK file
  5. Verify file appears in Project window

Tip: Create a "Scripts" folder to organize your files

2
Setup SDK Component
  1. Create empty GameObject (GameObject → Create Empty)
  2. Name it "MultiplayerManager" or similar
  3. Select the GameObject in Hierarchy
  4. Click "Add Component" in Inspector
  5. Search and add "SDK" component

Tip: Place this GameObject in your main scene for persistence

3
Configure & Initialize
  1. Get your API token from dashboard
  2. Set token in SDK Inspector field (Api Token)
  3. Get your private API token for player operations
  4. Set private token in SDK Inspector field (Private Api Token)
  5. Create new C# script for game logic
  6. Download example code for reference
  7. Replace YOUR_API_TOKEN and YOUR_PRIVATE_API_TOKEN with actual tokens

Tip: Store API token in ScriptableObject for production

Testing Your Setup
  1. Attach your game script to a GameObject
  2. Add reference to SDK component
  3. Press Play in Unity Editor
  4. Check Console for SDK initialization
  5. Verify API calls work (test with RegisterPlayer)
Production Checklist
  • Secure API token (don't hardcode in builds)
  • Enable IL2CPP for mobile builds
  • Test on target platforms
  • Handle network errors gracefully
  • Implement proper authentication flow
Common Issues & Solutions

Compilation Errors:

Ensure .NET Framework compatibility in Player Settings

API Timeouts:

Check internet connection and API token validity

JsonUtility Issues:

Use [Serializable] classes and proper field names

Coroutine Problems:

Start coroutines from MonoBehaviour instances

50+
API Methods
25+
Response Classes
100%
JsonUtility Compatible
IL2CPP
Mobile Safe

Unity Scripting API

Complete Unity-compatible API documentation for multiplayer games

MultiplayerSDK

Main SDK class for Unity multiplayer functionality

Description

The MultiplayerSDK class provides complete multiplayer functionality for Unity games. It handles player management, matchmaking, game rooms, real-time actions, and leaderboards with full JsonUtility compatibility for Unity serialization.

Public Methods

void SetApiToken(string token)

Sets the API authentication token for all requests

void SetGamePlayerToken(string token)

Sets the player authentication token for player-specific operations

string SerializeToJson<T>(T obj)

Serializes object to JSON using Unity's JsonUtility

T DeserializeFromJson<T>(string json)

Deserializes JSON to object using Unity's JsonUtility

Player Management

Methods for player registration, authentication, and lifecycle management

RegisterPlayer

void RegisterPlayer(string playerName, string playerDataJson, Action<RegisterPlayerResponse> callback)

Registers a new player account. The playerDataJson should contain initial player data as a JSON string for Unity compatibility.

LoginPlayer

void LoginPlayer(Action<LoginResponse> callback)

Authenticates the player using the currently set game player token. Returns complete player information.

SendPlayerHeartbeat

void SendPlayerHeartbeat(Action<HeartbeatResponse> callback)

Sends a heartbeat to maintain the player's connection. Call every 30-60 seconds to prevent timeout.

LogoutPlayer

void LogoutPlayer(Action<LogoutResponse> callback)

Logs out the current player and invalidates their session. Updates last logout timestamp.

ListPlayers

void ListPlayers(Action<ListPlayersResponse> callback)

Lists all registered players. Useful for admin dashboards or player discovery systems.

Game Data Management

Methods for managing global and player-specific game data

GetGameData

void GetGameData(Action<GameDataResponse> callback)

Retrieves global game data and settings. Data is returned as JSON string for Unity compatibility.

UpdateGameData

void UpdateGameData(string dataJson, Action<UpdateDataResponse> callback)

Updates global game data. The dataJson should contain the fields to update as JSON string.

GetPlayerData

void GetPlayerData(Action<PlayerDataResponse> callback)

Retrieves player-specific data. Requires player authentication token to be set.

UpdatePlayerData

void UpdatePlayerData(string dataJson, Action<UpdateDataResponse> callback)

Updates player-specific data. The dataJson should contain fields to update as JSON string.

Time Management

Methods for server time synchronization

GetServerTime

void GetServerTime(Action<TimeResponse> callback, int utcOffset = 0)

Retrieves server time with optional UTC offset. Useful for time synchronization and anti-cheat measures.

Room Management

Methods for creating and managing game rooms

CreateRoom

void CreateRoom(string roomName, string password, int maxPlayers, Action<CreateRoomResponse> callback)

Creates a new game room. The creating player becomes the room host.

ListRooms

void ListRooms(Action<ListRoomsResponse> callback)

Retrieves all available game rooms. Useful for server browser functionality.

JoinRoom

void JoinRoom(string roomId, string password, Action<JoinRoomResponse> callback)

Joins an existing room. Password required for private rooms.

ListRoomPlayers

void ListRoomPlayers(Action<ListRoomPlayersResponse> callback)

Lists all players in the current room. Useful for displaying player lists and checking occupancy.

LeaveRoom

void LeaveRoom(Action<BaseResponse> callback)

Leaves the current room and updates player status.

SendRoomHeartbeat

void SendRoomHeartbeat(Action<BaseResponse> callback)

Sends heartbeat to maintain room connection. Call every 30-60 seconds while in room.

GetCurrentRoomStatus

void GetCurrentRoomStatus(Action<CurrentRoomStatusResponse> callback)

Gets comprehensive room state including player lists and pending actions.

Room Actions

Methods for submitting and processing game actions

SubmitAction

void SubmitAction(string actionType, string requestDataJson, Action<SubmitActionResponse> callback)

Submits an action for processing by other players. Actions are processed asynchronously.

PollActions

void PollActions(Action<PollActionsResponse> callback)

Polls for completed actions from other players. Call periodically to check for new actions.

GetPendingActions

void GetPendingActions(Action<GetPendingActionsResponse> callback)

Gets actions awaiting processing by the current player. Call to find actions to complete.

CompleteAction

void CompleteAction(string actionId, string status, string responseDataJson, Action<CompleteActionResponse> callback)

Marks an action as completed with processing results. Used after processing pending actions.

Room Updates

Methods for real-time data synchronization between players

SendUpdate

void SendUpdate(string targetPlayerIds, string type, string dataJson, Action<SendUpdateResponse> callback)

Sends real-time updates to specific players or all players. Target can be "all" or JSON array of IDs.

PollUpdates

void PollUpdates(string lastUpdateId, Action<PollUpdatesResponse> callback)

Polls for updates sent by other players. Supports incremental polling with lastUpdateId.

Matchmaking

Methods for matchmaking lobby management and game start

ListMatchmaking

void ListMatchmaking(Action<ListMatchmakingResponse> callback)

Lists all available matchmaking lobbies. Useful for lobby browser functionality.

CreateMatchmaking

void CreateMatchmaking(int maxPlayers, bool strictFull, bool joinByRequests, string extraJsonString, Action<CreateMatchmakingResponse> callback)

Creates a new matchmaking lobby. The creating player becomes the lobby host.

RequestJoinMatchmaking

void RequestJoinMatchmaking(string matchmakingId, Action<JoinRequestResponse> callback)

Requests to join a lobby that requires host approval. Returns request ID for tracking.

JoinMatchmaking

void JoinMatchmaking(string matchmakingId, Action<JoinMatchmakingResponse> callback)

Joins a matchmaking lobby directly. Only works if lobby allows direct join.

LeaveMatchmaking

void LeaveMatchmaking(Action<LeaveMatchmakingResponse> callback)

Leaves the current matchmaking lobby and updates player status.

GetMatchmakingPlayers

void GetMatchmakingPlayers(Action<GetMatchmakingPlayersResponse> callback)

Lists all players in the current matchmaking lobby. Useful for displaying player lists.

SendMatchmakingHeartbeat

void SendMatchmakingHeartbeat(Action<BaseResponse> callback)

Sends heartbeat to maintain lobby connection. Call every 30-60 seconds while in lobby.

RemoveMatchmaking

void RemoveMatchmaking(Action<BaseResponse> callback)

Removes the matchmaking lobby and kicks all players. Only the lobby host can call this.

StartMatchmaking

void StartMatchmaking(Action<StartMatchmakingResponse> callback)

Starts a game from matchmaking lobby. Transfers all players to a new game room.

GetCurrentMatchmakingStatus

void GetCurrentMatchmakingStatus(Action<CurrentMatchmakingStatusResponse> callback)

Gets comprehensive lobby state including player status and pending requests.

CheckRequestStatus

void CheckRequestStatus(string requestId, Action<CheckRequestStatusResponse> callback)

Checks the status of a join request. Useful for tracking approval/rejection status.

RespondToRequest

void RespondToRequest(string requestId, string action, Action<RespondToRequestResponse> callback)

Responds to a join request (approve/reject). Only the lobby host can call this.

Leaderboard

Methods for competitive rankings and player statistics

GetLeaderboard

void GetLeaderboard(string[] sortBy, int limit, Action<LeaderboardResponse> callback)

Retrieves ranked players with configurable sorting criteria. Supports multiple sort fields.

HTTP Communication

Internal HTTP request handling methods

SendRequest<T>

private void SendRequest<T>(string url, string method, string bodyJson, Action<T> callback)

Internal method for sending HTTP requests with authentication and error handling.

SendRequestCoroutine<T>

private IEnumerator SendRequestCoroutine<T>(string url, string method, string bodyJson, Action<T> callback)

Internal coroutine for async HTTP requests with comprehensive error handling.

Utility Methods

Helper methods for JSON serialization and token management

SetApiToken

public void SetApiToken(string token)

Sets the API authentication token. Required for all API calls.

SetGamePlayerToken

public void SetGamePlayerToken(string token)

Sets the player authentication token. Required for player-specific operations.

SerializeToJson<T>

public string SerializeToJson<T>(T obj)

Serializes object to JSON using Unity's JsonUtility. Ensures Unity compatibility.

DeserializeFromJson<T>

public T DeserializeFromJson<T>(string json)

Deserializes JSON to object using Unity's JsonUtility. For parsing API responses.

Response Classes

Data classes for API responses with JsonUtility compatibility

BaseResponse

Base class for all API responses with success/error fields

RegisterPlayerResponse

Response from player registration with player credentials

LoginResponse

Response from player login with complete player info

CreateRoomResponse

Response from room creation with room details

CreateMatchmakingResponse

Response from matchmaking lobby creation

LeaderboardResponse

Response from leaderboard with ranked players

TimeResponse

Response from server time with timezone information

GameDataResponse

Response from game data retrieval

PlayerDataResponse

Response from player data retrieval

UpdateDataResponse

Response from data update operations