LiteNetLibGameManager extends LiteNetLibManager with requests, scene loading, player readiness, objects, RPCs, and state synchronization. The game request IDs (GameReqTypes) are carried inside the request/response message types (GameMsgTypes.Request and Response); they are not separate top-level packet IDs.
- The server accepts a transport connection, assigns a connection ID, and creates a
LiteNetLibPlayer. - The client's
OnClientConnected()sendsSendClientEnterGame()unlessdoNotEnterGameOnConnectis true. The request contains the packet version and any bytes written bySerializeEnterGameData. - The server's
DeserializeEnterGameDatachecks the request. The default implementation compares packet versions. On success, the enter-game response contains the connection ID and currentServerSceneInfo. - The client stores
ClientConnectionIdand loads or initializes the server scene. On later server scene changes,GameMsgTypes.ServerSceneChangecarries the new scene information. - After the online scene is ready, the client sends
SendClientReady()unlessdoNotReadyOnSceneLoadedis true. The server callsSetPlayerReady, which marks the player ready, spawns the player prefab when configured, and invokesDeserializeClientReadyData. - The interest manager subscribes the ready player to eligible objects. Spawn state is queued for delivery to that client.
Client Server
|---- transport connect ------>|
|---- EnterGame request ------->| validate version/custom data
|<--- EnterGame response -------| connection ID + scene info
| load/initialize online scene |
|---- ClientReady request ----->| mark ready, spawn player
|<--- subscribed spawn state ---| object IDs + initial state
The built-in top-level message IDs include Request = 0, Response = 1, RPC = 2, SyncBaseLine = 3, SyncDelta = 4, and ServerSceneChange = 6. GameReqTypes.EnterGame = 0 and ClientReady = 1 identify requests within the request message. See part 1 when registering custom packet IDs.
Override the matching writer and reader on your game manager:
SerializeEnterGameData(NetDataWriter writer)on the client andDeserializeEnterGameData(uint requestId, long connectionId, EnterGameRequestMessage request, NetDataReader reader)on the server. The reader returnsUniTask<bool>; if overriding it, preserve version validation as needed.SerializeClientReadyData(NetDataWriter writer)on the client andDeserializeClientReadyData(uint requestId, long connectionId, NetDataReader reader, LiteNetLibIdentity playerIdentity)on the server. The reader returnsUniTask<bool>;playerIdentitycomes fromSpawnPlayerand may be null when no player prefab is configured.
Write and read the custom fields in the same order. Keep the automatic enter-game and ready flags aligned with your UI flow. For objects and subscriptions after ready, continue to part 3.