About

Big Bad Robots is an indie game developer but we also do contract development. We have developed on all kinds of platforms (PC,Handheld,Consoles) but now primarily focus on iOS,Android and Unity. Contact us if you looking for developers with over 20 years experience in software and game development at biz -at- bigbadrobots.com

Unity3D networking Part 2, Making connections

March 18, 2011terence

This post is a follow up to my first one which gives you some concepts on working with networking. In this post, I will cover getting an a client/server connection going which is the first thing you have to do in building a multiplayer game. Your first point of reference is to make sure you are familiar with the Unity3D Network class which provide most the functionality you need to manage an initial network session.

I would like to cover some Unity3D specific topics on how networking is handled. Unity uses a Network View Component that is attached to every game object who’s state you want to synchronize with. It also allows you to send messages directly to those objects because each one is issued a network ID. The following picture should make things clearer:

Let’s also cover the ‘responsibilities’ in networking between the Client and Server.

  • The Server’s primary responsibility is managing the network session and propagating/validating state changes to connecting clients. It is also responsible for control of non-player game objects(i.e. enemies) by creating them when needed, running the AI routines which tell them to move. There are 2 modes that the server can operate under, authoritative and non. Authoritative servers have more work because they have to validate state changes from the client rather than merely passing it along to other clients. This is usually a slower way to operate as each move, action needs to be checked. If found to be invalid then the client that sent this original state changes need to be ‘brought in line’ with the way the server is thinking. A non-authoritative server on the other hand is more of a delivery person who simply relies information over to connected clients
  • The Client is responsible for the view of the world a player sees and for receiving input and forwarding it over to the server. In a non-authoritative mode, the client can also process game logic (i.e. decrease health, move  the player, move other objects) and these are sent to the server to be relayed to the other clients.

Most of the information from this posting are taken from the Unity iPhone multiplayer and the Unity Networking Example.

The first step in getting a network session up and running is initialize a server, which should be done when a level in the game loads up. This is done using the method on the Network class called “IntializeServer“. The first parameter is the number of connections to take. The second the listening port for the server, which is used by the clients to determine which application to connect on the server (as a server may be running multiple network applications). The last parameter if Network Address Translation should be used or not. All these except for the number of connections should be eventually made user configurable when you are writing your game.

Once the server is running, clients can connect using the Network.Connect method. The most important parameters for now is the ip address of the server and the remote port(which was the listening port specified earlier when the server was initialized).

That’s pretty much all there is for setting up a session. Be sure to check the Network class for more information on how to handle disconnects and network failures.

2 responses to “Unity3D networking Part 2, Making connections”

  1. […] please leave a message below and I’ll be in touch. Meanwhile, check out  the Part 1 and Part 2 Unity3D Networking Concept by Terence […]

  2. Chrystiano Araújo says:

    It´s really an excelent post.

    I hope to read more about Unity3d networking here.

    Thank´s.

Leave a Reply

Your email address will not be published. Required fields are marked *