Ultimate Unity Networking project - Add multiplayer to your game today!

This forum post discusses my Unity asset store package, the “Ultimate Unity Networking Project” which is available on the asset store.

Download it here

The project introduces you to networking in Unity and requires no previous networking knowledge. Basic Unity and scripting knowledge is assumed. Next to being a learning resource, the project also contains resources to make implementing networking in your games easier.

Feel free to add your feedback/suggestions/requests here

Project overview:
Actual Unity scenes in the project.

Documentation
The key of this project is the pdf documentation, it’s contents:


New features compared to the “Unity Networking: the Zero to Hero guide”
The zero to hero guide formed the solid basis for this project. The zero to hero guide is my successful 2.X Unity networking tutorial which was released for free August 2009. Besides some general polishment, this what’s new compared to the 2.X guide:

  • The project is now 3.X compatible.
  • The project is still in JS, but every file is available in C# as well.
  • new Tutorial: Tut #4, Manually instantiate networkViewIDs
  • new Example 5: Automatic matchmaking in-game (no usage of GUI, see Crashdrive 3D)
  • My custom MultiplayerFunctions class is included. Basically a network wrapper. Contains several timesaving functions/tricks.
  • Better/New documentation on: Masterserver, NAT/Connection troubleshooting, performance/LAG, load data before connecting, tips.
  • The package is maintained for Unity 3.

Awesome! Hope it gets approved pronto :slight_smile: I got my asset store account activated finally.

Does the NAT punchthrough in your new masterserver example work properly out of the box? That seems to be the biggest hurdle that everyone seems to have difficulty overcoming.

Problem with connecting/NAT punctrough come forth from: 1. Unity itself, 2. the master server, 3. your own code implementation, 4.the routers of host and client.
The main evils are 1,2 and 4.

Unity 3.1 has some networking bugs so using this project on 3.1 will still not work perfectly, but Unity will have this covered:). I have added my custom network class which wraps the StartServer and Connect functions, these do the connection testing, master server setup and NAT stuff for you properly. So with this package you won’t have to care about NAT/connection issues any more: If it still doesn’t work(Unity bug/Router issue) it’s out of our reach. And I’m keeping the package up to date for you.

So the short answer is: Yes this package could be an improvement for your connection issues as it takes it out of your hands. But we need to wait for the Unity bugfix for a big improvement.

If it make it work anywhere near as good as your master server implementation in CrashDrive3D, I’m sure it will be great :slight_smile:

It should be equal/better than Crashdrive and very similar to Cubelands. But as I said, an upcoming bugfix will be of most help for connectivity.

Live on the asset store, that quick!

Wow, that was fast!

Leepo,
I just finished working through your Zero to Hero guide and it was very enlightening. Great work and Thank You! I am glad your 3.x just came out and am looking forward to using your work and helping you earn the rewards you deserve (money). However, I am new to networking and I am left wondering how I get my game to move from my computers to my house’s LAN (that’s within our router, right?) and then out into the world. Will you cover that?

Also, I’m confused by Unity’s Master Server idea. I would like my game to be accessible through a controlled Lobby of my own design on my own server. Can I do that with “Built in Unity Networking”? or do I need Smartfox or similar? If I use Smartfox, do the scripts in your tutorials still work, or do I have to learn other things.

Will these points be covered in your Tutorial or do you have links where I can find the answers I need?

Thanks,
V

Purchased and Downloading!

(… and I still need help with those questions I asked!)

Most isp’s will frown heavily on running any sort of permanent server from your account. When they notice the traffic your service will be terminated right away. Not a problem if your game isn’t too popular, but if it takes off… Read your customer agreement.

There’s also the factor of your available upstream bandwidth. It might not be enough to support more than 8-10 users depending on your game.

You can do that with a Unity client in dedicated server mode, but there will be a limit to the scalability. Go read some of the old posts by Jashan in regards to his tron game for metrics and his experiences. He was able to get 70 users or so, iirc, out of one Unity based server. That’s an action oriented game.

As always your mileage will vary, according to the constraints of your own game and it’s traffic/load on the server. You can ease things a bit by having a slimed down server, running different code, by using compiler directives to excise most of the client stuff and vice versa.

If you want a truly scalable server, then you will need to go with Photon/Electroserver or Smartfox, depending on whether you’re running an action game or a turn based card game (UDP vs TCP). Either way, even with Unity networking, you will need a dedicated server or a VPS to run the server instance and/or a master/lobby server. Your home LAN isn’t going to cut the mustard.

No they likely aren’t covered as they’re outside the scope of his document. Setting up the master server yes, photon/smartfox no.

Purchased, and downloaded :slight_smile: good stuff! Love the new master server example with the wrapper.

@Legend411: Great, I’m curious what you’re working on.

Here some additional comments next to Quietus’ reply :).

Thanks!

I do have half a page covering connection issues in the document. Furthermore if you are using my MultiplayerFunctions script to connect and use the master server stuff, then you can;t be doing anything wrong on this area: I keep the class up2date to ensure maximum connectivity. However there currently some bugs regarding NAT/connection success; these will be fixed by Unity soon.

An RTS like lobby is in the examples. However you probably want more customization? Do note that you can use the master servers comment field to store a lot of custom data/properties (Server is Dedicated, has custom textures, is deathmatch etc.). I do this in Cubelands.
You can modify the masterserver (source code is available) and host it on your own server. But you can not customize the Unity end regarding registering and fetching the host list so you can’t extend that on the server either. In cubelands I register servers to the master list and use this to connect. But to easily enable a server list on my website I also have server register to my custom php/mysql webend (see here).
You could take that a bit further and fully integrate your own server lobby data in the game via php/mysql.

Smartfox/Photon or any other networking library all work a bit different and are not covered in this tutorial. I only have a list of networking alternatives naming them. I do plan to use Photon some time and write a similar tutorial for it, but that won’t be any time soon just yet.

Let me know if you still have any open questions after Quietus and my replies.

I’m working on a First Person Shooter and I’d like to get networking implemented. I come from a design background, so my knowledge of scripting is limited and I have absolutely no networking knowledge. I was reading through your Documentation overview, and I noticed that one of your examples is a FPS game. What does that entail exactly? Will I be able to use that as a foundation to my game? Was that specifically written to allow testing on one machine, or will I be able to get that working over a LAN with two computers without much trouble?

Thanks!

Thank you Quietus and Leepo for your patient and detailed (and prompt!) replies.

After going through this Tutorial, I have found that the Masterserver Example 2 works beautifully, straight out of the box. I put a build up on my web site, connected to a game from two different computers in my house, then had a friend across town connect and that worked also.

I am up and running the very next day after I started going through your tutorial!
I started with the 2.x version. It’s just dumb luck that you released 3.x the very next day!

Beautiful work, Leepo. You are a gifted programmer, writer, and teacher.
Thank you.

I know, right? It’s freakin’ sweet.

Question Leepo: I noticed you referenced this article when referring to unity fixing issues with the master server, but I don’t see anything mentioned about networking in that post.

@ Vimalakirti
@ legend411,

Maybe you guys could give me some insight on the question I asked above?

Oh, sorry, missed that somehow.

You could absolutely use his FPS example as a jump-off point for developing your own multiplayer FPS. Out of the box it already handles connecting to the public unity master server, creating a server browser gui, establishing a connection between clients and hosts, loading the subsequent game scene, spawning player prefabs for connected players, and some basic examples of network synced movement and shooting systems to get you started.

It will work over the internet, over your lan, or you could even connect to yourself by building out a standalone, hosting a game in the editor and connecting to it from the standalone via your loopback address (127.0.0.1). That’s actually the best way to do all your debugging, as it will operate exactly as it would over a network.

Unless you are testing for latency, lol. ping = 1.

Well yeah, I just meant like making sure all your syncing, RPC’s and stuff are working how you want and checking how many bytes per second you’re transmitting… real world latency and whatnot you’ve gotta get some friends online :slight_smile: