Online Play
Online play is optional and uses Netcode for GameObjects 2.x. Install it from the Package
Manager (com.unity.netcode.gameobjects). The kit’s online code, in
Integrations/NetcodeForGameObjects, is compiled only when the package is installed; without it
the rest of the kit works and the sample’s Play Online button hides itself.
The sample
Section titled “The sample”Open the sample menu and choose Play Online, or open
Integrations/NetcodeForGameObjects/Sample/Online.unity.
- One player presses Host. Their device runs the match and they play on it directly.
- The other enters the host’s address and port and presses Join.
- The match starts when both are in. Each player brings the deck chosen in their deck builder.
To try it on one computer, make a build, run it, host in the build and join from the editor with address 127.0.0.1.
How it works
Section titled “How it works”Netcode for GameObjects only carries bytes. The kit sends its own messages as Netcode named
messages on a reliable channel; there are no NetworkObjects, RPCs or network variables. The
rules, and the protection of hidden information, are the same MatchHost that runs local
matches:
- The host is authoritative. It holds the only full game state and checks every command.
- After each command, each player is sent only what they may see. Cards in the opponent’s hand and in both decks never leave the host.
- A player who disconnects during a match concedes it.
NetcodeHostTransport serves remote players through Netcode and the hosting player through an
in-process connection. NetcodeClientTransport is a remote player’s end. The same host
transport works as a dedicated server: start the NetworkManager with StartServer and seat
computer players or only remote ones.
NetcodeBytes.Configure raises UnityTransport’s maximum payload size, because a full match
update can exceed its 6 KB default late in a game.
Not included
Section titled “Not included”Matchmaking, lobbies, relay servers and reconnecting to a match in progress are not part of the
kit. They can be added on top: Unity’s Multiplayer Services work with Netcode for GameObjects,
and MatchHost.OnClientDisconnected can be overridden to keep a seat open instead of conceding.
Using another networking library
Section titled “Using another networking library”Implement IHostTransport (five members) and IClientTransport (two members) over your
library, and create the host and clients with them. See
Extending the Kit.