Dec/31
2009

Tutorial #3 - A quick and easy guide to creating multi-user environments in Unity 3D

Welcome back, I haven't written a tutorial in a while so I thought I would make this one worth having waited for.

The purpose of this guide is to help you, the developer, to create a networked virtual environment without having to do any coding whatsoever. It goes without saying that the fastest methods of content creation are usually the best when working as an independent professional (or even as a member of a small team). With that having been said, I'm aware that this information is highly sought after and that I could probably benefit more by selling it as an eBook. As things are however, I will be providing this information free of charge (88|) with the only cost being for the project file ($2), should any of you want it. Moving on, we need to discuss the following...

  • The difference between an authoritative server and a non-authoritative server
  • The different server solutions Unity supports
  • The SmartFox multi-user server

  • An authoritative server, understood in the context of gaming, is a process which simulates the virtual environment and updates all clients/users with objective data. As an example, if we imagine a group of physics objects colliding with one another, an authoritative server would simulate the collisions by itself and update the client(s) as changes occur whereas a non-authoritative server would simply ignore the complexities involved with the simulation and not bother updating the clients (which then leads to inconsistencies regarding what each user sees). An authoritative server is significantly more complex to create/set up than an otherwise non-authoritative version, it is also more demanding of system resources. This is an incredibly brief summary of a subject which is infinitely more complex than I have hinted at here but, for now, that's all you need to be aware of. We're going to look at a non-authoritative solution, just the very basics. Unity does have its own built-in solution for creating multi-user environments. It is, however, a bit more complex to set up than the method I am about to show you. Some alternatives to Unity's integrated solution are SmartFox, NetDog and Photon. Today, we'll be looking at SmartFox. A bit of background, to quote from the SmartFox website:

    SmartFoxServer was originally designed to specifically target Flash Player based applications and games. Thanks to its popularity it has quickly gained interest among other technologies such as Java, Director, .Net/Unity 3D etc...

    So, moving on to the first step on the next page...

    Pages: 1 · 2 · 3 · 4 · 5





    46 comments
    Comment from: Martijn Zandvliet [Visitor] · http://www.synthode.com
    Great stuff! Look at how cute those little green capsules are, awwww.
    01/01/10 @ 11:36
    Comment from: Virtual Autonomy [Member] Email
    Yes, watch out for Green Capsules Online, the only real free sandbox MMO coming your way soon.! ;p

    Hehe, I didn't want to give away any models. This really is bare bone stuff.
    01/01/10 @ 17:17
    Comment from: steve [Visitor]
    Your stingy (couldn't resist saying it).
    01/04/10 @ 13:42
    Comment from: David Golds [Visitor] Email · http://mygamebuilder.com
    Nice article. I wish I'd found it 3 months ago.. sigh!

    Also, take a look at ExitGames' Photon server - http://blog.exitgames.com/?p=677
    01/05/10 @ 09:02
    Comment from: Sentinel3dsm [Visitor]
    this realy sounds great!
    but i got some problem when importing the package... when i push the import button unity crashes
    01/15/10 @ 21:21
    Comment from: Virtual Autonomy [Member] Email
    Sentinel, which version of Unity are you using?
    01/17/10 @ 18:31
    Comment from: Sentinel3dsm [Visitor]
    hehe... sorry! i had 2.5
    you need 2.6 (maybe good idea to put it in front of your tutorial)

    so now it works! now i can finish my game... Great WORK!! thnx
    01/17/10 @ 19:41
    Comment from: Mirage [Visitor]
    When I run the game I get an error on line 62 of the LoginGUI.cs script (smartFox.ProcessEventQueue). Any Idea what causes this?
    01/23/10 @ 19:29
    Comment from: Gotmilk [Visitor]
    Hey Zante,

    Great tutorial you have here. This is probably very stupid question, but how do you host your server? Do you have a personal computer acting as a webserver and it has smartfox service running?

    Or do you have a host somewhere where you can run your server and you got smartfox to run there 24/7 ???
    01/26/10 @ 07:11
    Comment from: Virtual Autonomy [Member] Email
    Gotmilk, good question. You need to make sure that you have a static IP address or a DNS routing service. That way, if your connection goes down, once it comes back up people will still able to connect to it.

    I host my server from my office at the university. I have a machine dedicated to acting as a server for a few projects I'm working on.

    If this is a problem for you, try asking around on the smartfox forums for more hosting solutions.

    01/26/10 @ 15:12
    Comment from: Milos Stojanovic [Visitor]
    I love this tutorial! Once correction though, I think you forgot one important step in making player able to see remote player.. Add remote player prefab to player spawn controller. Other then that little thing this tutorial totally rocks.
    01/27/10 @ 13:56
    Comment from: Fabio [Visitor] Email
    Can u give me the unity 3d project files free, i dont have paypal. Please :(
    02/17/10 @ 17:03
    Comment from: Virtual Autonomy [Member] Email
    You don't need a paypal account, you can just use a credit card when the option comes up. To ask me to pass it on for free when it's so cheap is something I can't do, sorry. :[

    If you need any help regarding the tut just ask.
    02/20/10 @ 11:55
    Comment from: Tomaz Saraiva [Visitor] Email
    First of all I have to thank you for saving my life. This was exactly what I was looking for eheh

    Although I have one question. In my game I have an elevator and i want to synchronize it between both players. My goal is that both players can use the elevator together.

    How can I do this?

    Thanks for any help
    03/13/10 @ 22:54
    Comment from: Malidian [Visitor]
    I'm getting this error when I hit play to test connection...

    Assets/Pro Standard Assets/Image Based/BlurEffectIsland.cs(131,25): error CS0103: The name `ImageEffects' does not exist in the current context
    03/15/10 @ 22:44
    Comment from: Malidian [Visitor]
    I was missing the ImageEffects.cs...i found one online and it had this problem

    "Unsafe requires 'unsafe' command line something....i couldn't figure that out so i just removed all the scripts that were giving errors until it worked. I removed the BlurrEffectIsland.cs, GlowEffectIsland.cs, UnderwaterEffects.js...I don't have the pro version, I am sure this is why it did not work or why I did not have the right ImageEffects.cs...If all I was missing was the correct ImageEffects.cs then maybe someone can provide that.
    03/15/10 @ 23:48
    Comment from: Intertricity [Visitor]
    For some reason the character keeps falling through the floor. I'm using the free Unity3D 2.6, I removed the pro assets and water asset to stop errors. Any idea what's wrong?

    Also, I bought the project file but haven't gotten any email back with a download link.
    03/28/10 @ 19:53
    Comment from: Antonio [Visitor] · http://www.unity-rf.info
    Thanks you!

    Buy i have an error:

    SendMessage StartSending has no receiver!
    UnityEngine.Component:SendMessage(String, Object, SendMessageOptions)
    UnityEngine.Component:SendMessage(String, Object, SendMessageOptions)
    UnityEngine.Component:SendMessage(String)
    PlayerSpawnController:SpawnLocalPlayer() (at Assets\Game\Scripts\network\PlayerSpawnController.cs:26)
    PlayerSpawnController:SpawnPlayers() (at Assets\Game\Scripts\network\PlayerSpawnController.cs:17)
    UnityEngine.Component:SendMessage(String, Object, SendMessageOptions)
    UnityEngine.Component:SendMessage(String, Object, SendMessageOptions)

    What is happend?
    03/30/10 @ 22:37
    Comment from: ashwan [Visitor]
    can u convert the same tutorial into a 3rd person view . i tried it but was not succesful
    04/06/10 @ 12:56
    Comment from: TJ [Visitor] Email
    for the first part where you have to test the login scene where you see if it works at all in order for you to go on, i keep getting an error having to do with the pro standard assets saying that the image effects command at line 131, column 25 for the blureffectsland script does not exist in the current context, because of this, im not able to test the login scene at all because of the lousy thing. What should I do?
    04/16/10 @ 04:44
    Comment from: Virtual Autonomy [Member] Email
    If you haven't got an email to download the link from, check your junk folder. It's worked for countless others thus far and I don't think the problem's on my end. :[

    If you are not using the pro version of Unity, you'll have to delete references to those missing assets. I will remove the references at some point but I currently have 6 other projects to attend to (hence the lack of blog updates).

    Just comment out the line(s) referencing ImageEffects.cs
    04/16/10 @ 14:58
    Comment from: TJ [Visitor]
    hi
    i got the first problem fixed, but now im wondering that when you do a first attempt test connection, after i put in all available ip addresses &port numbers, i keep getting an error stating "connection refused" or "connection timed out", i found that in the config file it stated the server port as 9339 for its default, i am too afraid of putting it as 3000 since it might mess it up, what should i do?
    04/16/10 @ 17:34
    Comment from: TJ [Visitor]
    ps i forgot to mention that i live in a community where all the routers go through the default gateway router before actually going into the internet
    04/16/10 @ 17:57
    Comment from: ev [Visitor]
    how do i get this live? like do i have to change the config.xml to my ip? or something like that?
    04/16/10 @ 18:45
    Comment from: Dragos [Visitor] Email · http://www.cucurigul.ro
    Hi,
    Thank you so much for this tutorial, it's simple and amazing.

    I have some objects in my scene that can be moved by the player. The only problem is that the remote player doesn't see the object moving.

    You have any tips on how to do this?

    Regards,
    Dragos
    04/27/10 @ 20:23
    Comment from: Nallac [Visitor] Email
    Great tutorial it all works but when i move it crashes immediatly so i can only jump how do i fix that?
    05/16/10 @ 06:14
    Comment from: Sunroc [Visitor]
    great tutorial and very easy to use :)
    05/28/10 @ 23:32
    Comment from: thomas [Visitor] Email
    please help me i have 2 problems :(

    problem 1
    SendMessage StartSending has no receiver!
    UnityEngine.Component:SendMessage(String, Object, SendMessageOptions)
    UnityEngine.Component:SendMessage(String, Object, SendMessageOptions)
    UnityEngine.Component:SendMessage(String)

    problem2
    Assets/Pro Standard Assets/Image Based/BlurEffectIsland.cs(131,25): error CS0103: The name `ImageEffects' does not exist in the current context

    please help me :(
    06/19/10 @ 18:07
    Comment from: Maarten [Visitor]
    Great but i got an error... on smartfox
    06/25/10 @ 19:21
    Comment from: Maarten [Visitor]
    I fixed it if anyone has problems on this just move the smartfox file out of the program files file(uninstal and reinstal on desktop or something doesn't matter just not program files!)

    Then it should work fine if you run it!

    06/25/10 @ 19:52
    Comment from: Tate [Visitor] Email
    PLEASE HELP ME!!!!

    i am getting an error that says

    Assets/Pro Standard Assets/Image Based/BlurEffectIsland.cs(131,25): error CS0103: The name `ImageEffects' does not exist in the current context

    What should I do?????
    06/30/10 @ 21:20
    Comment from: robbilie [Visitor] Email
    do i have to buy the project files ( i did it a few minutes before)

    or am i able to do this without:

    when i run around... i only see the player at the spawn point in the air... im walking with the other player but in the other window hes at the same place...

    why?

    thx
    07/04/10 @ 17:57
    Comment from: tom [Visitor]
    When I open the login scene and i press play its a white screen should i quit now?it has the skin applied

    thanks
    07/05/10 @ 21:23
    Comment from: Deniz Opal [Visitor] · http://xsentrikworlds.com
    Hi there

    Can you tell me what the difference between the "local player" item and the "remote player" prefab is? why do we need both?
    07/10/10 @ 02:21
    Comment from: mbreen [Visitor] Email
    I downloaded the bare bones file and i got 57 folders with long and random names each with some unix files. How do i import these into unity?
    08/06/10 @ 03:03
    Comment from: fjonken [Visitor] Email
    thank you for the tutorial, its really helpfull! but, i can connect to the game using 2 clients and i can write and so on, but i cant see the other player, he is like invisible,but i dont get any erros, the character is jusst invisible. can anybody help me? please!?
    11/07/10 @ 19:23
    Comment from: joe [Visitor]
    Hi,

    I bought the 2 dollar project file and am having some trouble. I built and ran the executable on two different machines. I cannot see either instance of the player (capsules). However, when I run the executable twice on one machine, it does work..
    12/02/10 @ 05:33
    Comment from: Virtual Autonomy [Member] Email
    Some of you have been having trouble with the project file. This is partly due to the problems which came with Unity v3.0 which is a lot more security conscious. The networking project file currently works offline but not online.

    Make the following changes:

    1. Add Socket Policy prefetch line at end of Awake() in LoginGUI.cs
    Security.PrefetchSocketPolicy(serverName, serverPort);

    2. Use SmartFoxClient.dll that is compatible with SFS 1.x

    You can get a working .dll from a zip download of a modified version of the SFS island Demo for SFS 1.x in a comment by "lastowl" in
    http://www.smartfoxserver.com/forums/viewtopic.php?p=41732

    Thanks for your time. I will be releasing a new networking tutorial which makes use of php requests in the near future. ;]
    07/12/11 @ 16:26
    Comment from: Vus [Visitor]
    hi, i have problem with step three.
    i unpack packpage, move it to project folder, but i cant open that scene.
    it says: Error while importing package: Couldn't decompress package

    could you please help me?
    07/23/11 @ 11:30
    Comment from: Virtual Autonomy [Member] Email
    Which version of Unity are you using?

    Have you tried this with a new project?

    Are you using the $2 project file?
    07/23/11 @ 15:03
    Comment from: Vus [Visitor]
    Version 3.3.0f4 (63135)

    Yes

    No
    07/23/11 @ 18:40
    Comment from: Todd Drexel [Visitor]
    I'm having trouble with the free project going through this with Unity version 3.3 I believe it is, getting errors after importing the package you had supplied. However I noticed just a couple comments up you have listed a couple fixes, I can't get the SmartFoxClient.dll zuo from lastowl's comment in the smartfoxserver forum due to his hosting is down. Is there another way to get it?
    09/29/11 @ 08:47
    Hey i have some bug , the remote character keep falling under terrain and go up after 0,01sec ( time i set )
    i dont know how to fix it , im new with unity

    Here a video to see what happen :
    http://www.youtube.com/watch?v=d9FXsX7mGr8
    , every suggestion accepted , if you want to personally help me , i have teamviewer.
    11/05/11 @ 02:51
    Comment from: fzaers [Visitor]
    Hello!

    Thank you for the great tutorial!
    I am trying to work on a simple multi-player game and this have help me a great deal.

    Is it possible to implement individual object's behavior such as objects physics using your instructions( non-authoritative server)?

    Once again, thank you!

    11/08/11 @ 08:12
    Comment from: Viktor - FPS game ongoing - HELP! [Visitor] Email
    Hi, i maid the multiplayer work well and i can se the other player. Now i want to make my player shoot, the only problem is that the bullets only appear on the shooters screen and not on booth?
    Any Ideas? would be great!
    12/07/11 @ 16:37
    Comment from: Randy Cooper [Visitor]
    Hello, thank you so much for the tutorial I am sadly having trouble though. I am getting a message that says waiting for connection on the gui login screen, and the main level wont load :(
    01/08/12 @ 21:58
    Leave a comment

    Your email address will not be revealed on this site.

    Your URL will be displayed.
    (Line breaks become <br />)
    (Name, email & website)
    (Allow users to contact you through a message form (your email will not be revealed.)
    This is a captcha-picture. It is used to prevent mass-access by robots.
    Please enter the characters from the image above. (case insensitive)