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

Adam,
I would suggest working more on your FPS game play first, since that will help you learn more scripting, and networking is all scripting work. On the other hand, if you go ahead and buy this tutorial now, then you’ll have it, and you can start altering the FPS example until it’s your own and you’ll have the networking done too. If you’re confident that you will continue with the development of your game and the 60 bucks won’t hurt you, then go ahead and get it. But if you’re still just experimenting to see if you want to commit, then wait cause you can buy it any time.

I’m afraid I’m not very much help.

You will be able to get it working out of the box right away as the projects examples are ready to go right away. However to really customize it to your specific needs you’ll have to learn some scripting. But you would need to learn scripting to make the actual game(play) anyway. The FPS example has multiplayered movement/shooting a deaths/kills scoreboard. Picking up ammo and two pickups. You could try tweaking this example. This project does assume you have scripting knowledge so you’ll have to learn the actual scripting via other sources (Maybe try my free “C# game examples” project to learn C# coding easily).

Thanks everyone.

I understand that I’ll need to learn scripting which isn’t going to be a problem, I was only looking for a good starting foundation when it comes to multiplayer. I was looking at UDK and Torque 3D since they have a strong multiplayer foundation out-of-the-box, but I decided to use Unity for their strong community since my endeavor is solo for now. My plan is to “rough in” game-play; networking, functionality, features, etc. and then get to the asset development later since that’s my specialty. Anyways I look forward to picking it up!

“and connecting to it from the standalone via your loopback address (127.0.0.1)”
Can you explain this a little more please?
Thanks

Where was that stated? I’ll also update the description there.

Your own computer always has the localhost address (127.0.0.1) Wikipedia.
But yeah ignore the confusing “loopback” stuff. Next to your normal LAN IP you can always use localhost or 127.0.0.1 to point to your own computer, even if there is no connection.

Thanks, it was stated in legend411 post.

Sorry, didn’t mean to confuse you. Loopback address is just another way of saying localhost, its a network interface that allows a computer to send network messages to itself, so you can test things.

Hi! Just bought this to help me with my final exam project :smiley: (Game Design Development MBO Alfa College in Groningen)

Just one quick question, in a lot of scenes there is a object called “Persistent” that has a “MultiplayerFunctions” script attached and also one Mono Behaviour that is missing a script. What’s up with the missing script? :slight_smile:

Thanks!

I noticed that too… whats up with that?

I have the same question as legend411.
I have another question for Leepo, do you think this is suitable for an RTS ? I just need a peer-to-peer connections, a lobby, etc., and offcourse, all the RTS units.
Thanks

I’m pretty excited with all this, because I need a good solution for a RTS multiplayer game. But I still have a big doubt: where to host the master server. Is Google App Engine, for example, a good solution for a non-dedicated host (that is, simply for connecting players)? How much do you pay for your hosting services?

I set up a master server on a windows vps with root/rda access from http://www.ucvhost.com//VPS/EntryLevelVPS/EntryLevelVps.aspx using Zumwalt’s package: http://forum.unity3d.com/threads/75710-Master-Server-for-Service-on-Windows-Servers

He tweaked the code a little bit and I have had zero issues with NAT punchthrough so far, and that was the absolute cheapest hosting I could find for a windows server with remote desktop access ($9.99/mo), and it works great!

Sorry for the lack of reply, I was at a GGJ and was very busy there :P.

Cool, good luck with that project, I’m curious to your end result. Please let me know when it’s finished :).

@BigB, Legend, TheRedTape: (Persistent missing script)

Just submitted a minor update to fix that missing script issue:
“Small bugfix in three example scenes, the “persistent” object missed the MakePersistent script”

The missing script was the MakePersistent.js. This script simply marks its gameobject as DontDestroyOnLoad to make it persistent: We need it to easily ensure the MultiplayerFunctions.cs is available in all scenes.
If you first load the main menu, it’s “persistent” object (has MP functions + makepersistent attached) will be made persistent, therefore when you load the game scene this gameobject will still be around.

If you run the game scene directly from the editor the MultiplayerFunctions.cs needs to be present in the game scene. Thats why I -also- added the Multiplayer Functions to the game scenes now.This will not cause any problems. The MultiplayerFunctions script makes sure there’s max. only one instance of itself around at all times.

This small update should be available today/tomorrow I guess.

@LuisAnton

The Unity networking + masterserver works great. But whether you will want to switch to a different networking solution (and master server) depends on your own custom/specific needs. Unity can handle an RTS game, but what are your needs? Do you -need- to ensure 100% connectivity? Then you’d need your own dedicated servers running gameservers (e.g. Photon).
If you want to save costs and are fine with a bit less connectivity you can go for Unity.
I could see myself using Unity for an RTS game.

I have purchased and gone through the tutorial, as well as reading everything I can on the forums but I still have a few things I don’t understand.

First, I don’t see a good simple yet complete example of how to NOT use Network.Instantiate. All the tutorials use this, and then the guide says don’t use this. Most of the forum posts say not to use it as well, though never really explaining why. When I use it I get working networked objects, but nothing deletes on the server when clients disconnect, so I’m assuming thats the problem with it, but I don’t know.

Has anyone put together a step by step guide of network code only to explain how to do start using the non Network.Instantiate method? I tried remaking the steps from the tutorials without it but my client fails when it receives the RPC I am calling to instantiate my prefab client side because the prefab has no networkview ID yet. (At least I think that is what the error means)

Basically this is what I am doing, but I must be missing a step client side. (skipping all non network code to make this simple)

//SERVER
Network.InitializeServer(32,connectPort,false);

//CLIENT
Network.Connect(connectToIP, connectPort);

//SERVER
void OnPlayerConnected(NetworkPlayer player)
{
NetworkViewID viewID = Network.AllocateViewID();
//call instantiate on my prefab and add it to a list of players serverside (not Network.Instantiate)
networkView.RPC(“SpawnPlayerPrefab”, RPCMode.OthersBuffered, viewID, transform.position); //create the ship on all the clients manually because not using Network.Instantiate
}

//CLIENT
//spits out debug.log receive RPC debug message but my SpawnPlayerPrefab RPC is never called
//instead I get the following 2 errors;
View ID SceneID: 1 Level Prefix: 0 not found during lookup. Strange behaviour may occur
Could’t invoke RPC function ‘SpawnPlayerPrefab’ because the networkView ‘SceneID: 1 Level Prefix: 0’ doesn’t exist


It seems I need to create the network view client side first somehow, but I don’t know how else to tell the client about the network view ID the server just created other then the RPC I am using now, and I don’t know where else I would assign this view id to until I instantiate the prefab on the client which contains the network view for that object.

Thanks!

This is probably the key problem:
You do need at least one networkview to be able to pass and assign the allocated networkview ID. A networkview ID is automatically assigned when:

  1. Using Network.Instantiate (but I indeed disencourage using this)
  2. Adding a networkView to a gameobject in your scene (e.g. on your own GameSetup/GameManager object)

Your problem is that you are sending an RPC message on a gameobject that has no networkview attached…or it only has a networkview without a networkviewID assigned. You should add an gameobject to your scene with a networkview and your GameManager.cs script(or something along those lines). Then have that script spawn the players and use its networkview to set the networkView IDs.

This is showcased in Examlple 5 only. I indeed do not have a clear tutorial on this yet(!), but I will add it as Tutorial 4 :)!
I’ve started working on it right away.

I added a line to my network manager object that is called in the void OnConnectedToServer() method
m_MyViewID = Network.AllocateViewID();

This still gets the same errors when I send the RPC.

I am not exactly sure I am understanding what you are suggesting. What is the sequence you feel is best after a player connects to the server? I would imagine you then want the server to send a RPC to all clients to add another prefab to the game so the server would create the new network view ID, and pass this along and then when the clients get the RPC, then the clients instantiate the prefab and assign the network view ID which is what I believe I am doing here.

Thanks for the guide and the help BTW! :slight_smile:

If you can wait I might be able to finish the new “tuturoial 4” tomorrow and the update could be available on the asset store the same day.

Awesome! :slight_smile:

I’m about to finish tutorial 4 and upload the update to the asset store.
Here’s an PM I received I want to share:

While I could add the resources to tell you how to synch a texture or a physics object…it always depends on your custom needs. You should never synch more then required and the requirements vary per project. What’s more important is to get everyone to understand (1) what needs to be synched and (2) how that can be synched. It is vital to gain more understanding of the lowest-level data thats required to be networked.

Physics can be a pain in multiplayer. How authoritative does it need to be? How accurate? If it doesn’t affect gameplay; generally, don’t even bother to synch phsyics. What physics properties matter for the game? When networking physics, make sure to not only network the position/rotation but also the rigidbodies velocity and angular velocity(!).
Textures: Either send an int with a custom defined reference to a certain texture. If it’s a user-customized texture you can send the image data in a byte[ ] (and you might want to zip that).

@Scorch and everyone else
I have just submitted an update to the asset store.
The new Tutorial 4 is added with a clear and cut down example of manual instantiation of networkView IDs.