Network Types

There are 3 different network types you can use included in this asset. Each one have their own advantages.

  • Peer to peer (including LAN)

  • Dedicated Server

  • Relay Server

Peer to peer

Simplest way to connect and test since it doesn’t require you to host a server. All you need to do do is Host a game from the Menu scene, and then Join with another player using the host’s IP:

Local IP: 127.0.0.1 if running the game twice on the same PC.

Internal IP: 192.168.x.x (this is LAN, you can see the host internal IP in the menu).

External IP: x.x.x.x (you can google “what is my IP” to know this).

The disadvantage of this method is that the host needs to open ports and allow the application on their firewall. Also, if connecting with external IP, the host will need to setup port forwarding on their router. The default port is 7700 but it can be changed in the NetworkData settings in Resources folder.

Dedicated Game Server

A dedicated server means that there is no host, instead the host is a game server you upload on a cloud server, and run, that other people can connect to. This is a bit more complex to setup because you need to manage your own server.

There can only be 1 game per server app (although you can run the application multiple time on the same cloud server, each with a different port). To help with this, there is a lobby server (which is a separate build) that makes it easier for player to find other players, and that will automatically start and stop a new dedicated game server for each game room.

The advantage of this method is that there is no player host, so the game does not stop if the host leaves, and no one needs to setup port forwarding. But this method will require you to setup a server, and will require the most server processing power. Since the entire game logic runs on your server.

To build the dedicated server, put the ServerGame as the first scene, and make sure to also include all playable game scenes. Another document will explain how to install this.

For testing purposes, you can run the dedicated server locally on your pc, either from a build or from unity. You can also connect directly to a dedicated server in the same way you would connect to a host: from clicking on Join in the Menu and using the server’s IP.

Relay Server

Using a relay server can be used as a compromise between the other 2 methods. You will still have a host (so game shuts down if the host leaves), but the host won’t need to setup port forwarding and do not need to setup their firewall. The relay server does not handle game logic, but will act as a middleman, transferring all messages between the client and the host.

A relay server will require way less processing power than a dedicated server, but it will have the greatest delays, since all messages needs to transit through the relay, and if the relay is far from your host it may increase network delays.

In this asset, the offered relay server solution is with Unity Services Relay. More info here: https://docs.unity.com/relay/

To use it, you will need to link your project to a Unity ID inside the Services Window, and you will need to enable Unity Relay on your Unity dashboard: https://dashboard.unity3d.com/

Also you will need to change the protocol type on the UnityTransport to Relay.

At the moment, in this asset, you can’t connect directly to a relay server (since the process is a bit more complex). Instead, you need to connect through the lobby server in Relay mode.

Last updated