Skip to content

Tutorial 14: Two players, one court

You build the add-on’s own small game, then play it with yourself: one copy hosts, a second copy joins. Each copy plays one character, sees the other player’s character, and can propose an alliance. The question opens as a dialogue on the other player’s machine, and the answer comes back to the one who asked.

The sample uses only the public API of the add-on, so you can copy from it. To set up a game of your own, see Quick start with Netcode for GameObjects.

The Multiplayer add-on compiles on Unity 6000.0 and 6000.6. Two players were tested on 6000.0 (an editor host and a development player); not yet on 6000.6, over Relay or with IL2CPP.
  • Intrigues and Intrigues Multiplayer are in the project.
  • Netcode for GameObjects (com.unity.netcode.gameobjects) is installed: version 1.x on Unity 2022.3, 2.x on Unity 6. The sample’s scripts and its menu entry exist only when NGO is installed.
  • Edit > Project Settings > Player has Active Input Handling on Input Manager (Old) or Both. The sample’s EventSystem and the Intrigue System UI, which shows its dialogues and announcements, read the old Input Manager. If a dialogue’s choices do nothing, this is the cause.
  1. Save or discard the changes of your open scenes. The builder refuses while an open scene has unsaved changes.
  2. Choose Tools > MrW > Intrigues > Multiplayer > Build Two-Player Sample. A dialog Two-player sample asks whether to build. Click Build. The open scenes are closed while it builds and opened again when it is done.

It makes everything in a Generated folder: a small database of three characters (Aldric Varn, Maren Holt and Bram Ely) in two houses, with one scheme, Propose an Alliance; the sample settings; and two scenes, Two-Player Menu and Two-Player Game. Both scenes go to the end of the Build Settings, the menu first. Building again replaces the files in Generated.

Both copies need the same database, the same scenes and the same version of Intrigues and of the add-on.

  • Two editors. Open a second Unity editor on a copy of the project, and open Two-Player Menu in both.
  • A build and the editor. A build starts with the first scene of the Build Settings. Move Two-Player Menu to the top, or untick the other scenes, and make a build. Open Two-Player Menu in the editor and press Play.
  1. In Two-Player Menu, type a name under Your name.
  2. Leave Port at its value. Type a Password (empty: none) if you like.
  3. Press Host a game.

The status reads Hosting on port and the port, and Waiting for the other player. The host plays Aldric Varn. If it cannot host, the status says The game could not be hosted (is the port in use?). See the Console.

  1. Type a name, and the Host’s address: 127.0.0.1 on the same machine. Type the same port. If the host set a password, type the same one.
  2. Press Join.

The status goes through Connecting to the host…, Loading the host’s scene… and Receiving the world: with a percentage. The player who joins plays Maren Holt. Cancel stops the join.

In Two-Player Game, a box shows two lines. Its first line is You play: your character and your name. Until the other player joins, the host sees The other player has not joined yet. Afterwards both see The other player plays: the other character and the other player’s name.

Each player also has a button Propose an alliance to and the other character’s name, and a button Leave. On the host that button reads End the game.

Press the proposal button on one side:

Who What happens
The one who asks The box says Asking…, then The scheme started. or It did not start, with the outcome and the reasons.
The other player A dialogue opens with the title of the asker’s name, the text that starts with {target.Name}, filled in as the name, then “our houses would be stronger together. Will you stand with me?” and two choices: I will. and I stand alone.
The one who asked, afterwards An announcement, An Alliance (“stands with you”) or Refused (“will not stand with you”).

On the host the scheme starts at once. On the other machine the host checks the request and answers a few frames later. The world changes only on the host.

By the code, the other player sees the dialogue after you propose, and the answer comes back as the announcement.

To end, press Leave, or End the game on the host. The start screen says in plain words why a session ended: The host ended the game., You left the game. or The connection to the host was lost. A refused join says why too, for example The password is wrong., The game is full., Someone already plays that character. or The host runs another version of the game.

These stay visible on purpose. They are copied from the add-on’s own README. See Limits and what is not verified.

  • No one has made an IL2CPP player build.
  • Relay and a host on the internet are reasoned through, not played.
  • Runs with 4 and with 8 machines are still to come. The add-on is designed for 8 players at once, the host and 7 others, and more is not tested.
  • The Windows firewall prompt when a build hosts was not checked: no Windows machine was used.
  • This page has not been followed with two editors or with an editor and a player.
  • The menu entry is missing. NGO is not installed.
  • The dialogue’s choices do nothing. Set Active Input Handling to Both.
  • Nothing happens on join. Run Tools > MrW > Intrigues > Multiplayer > Check Project.
  • The join is refused for content. Make the same build for everybody.