Search Unity

  1. Unity 2019.2 is now released.
    Dismiss Notice

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

Discussion in 'Connected Games' started by MikeHergaarden, Jan 25, 2011.

  1. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,670
    Cozza13: You can check thru the Asset Store tab in the Unity3D editor.

    Look for the "download tray" for your "purchased" items.


    Check to see if it is "up to date". If so, it will say so. If it it not, it will day "download". Click the "download" button and you will start a new download:


    And then you'll have a new version!
     
  2. cozza13

    cozza13

    Joined:
    Dec 13, 2010
    Posts:
    64
    @littleangel that is perfect thank you
     
  3. zyndro

    zyndro

    Joined:
    Oct 19, 2010
    Posts:
    78
    i have a simple question, but i just cant figure it out..

    here's my scene..

    Let's say there's 2 guys that want to connect and play against each other in "x" game.. ok

    One guy lives in USA and has an ip lets say 16.48.32.120.. the other guy lives in Australia and has an ip lets say 125.43.112.32.. ok

    now here comes my question ( i know it's dumb but i just cant figure out how this is possible.. )

    If the guy in USA host a game, how it is possible to the guy in Australia join the game if they doesnt know each other's ip..

    i mean.. the guy in Australia press the button "search for games" how it can be that the game finds the hosted game of the USA guy?

    i know this sounds silly... but... does the Australian guy Scan The Whole Internet??? sounds absurd to me.. this would take hours.. isnt it?

    then how can be possible that this USA hosted game can be found by the Australian guy?

    sorry for my question, i just cant figure out how this can be possible..

    i know each player that host a game, host it locally, but i just see no connection link between them.. is there like a server manager in some server site that works as a "hook" point? where both guys Australian and USA guy connect and then they can stablish a connection?

    please explain me, because i dont get it.

    thank you so much and sorry my english!!!
     
  4. appels

    appels

    Joined:
    Jun 25, 2010
    Posts:
    2,685
    The master server is the one thats resposible for advertising games on client request.
    It holds the remote ip and the port to connect to.
    Without the master you would need to enter the ip address manualy.
     
  5. Spectre9000

    Spectre9000

    Joined:
    Aug 30, 2010
    Posts:
    170
    Does this have built in support for Photon?
     
  6. zyndro

    zyndro

    Joined:
    Oct 19, 2010
    Posts:
    78
    ok, but then.. this master server must be located in some server? so for example.. the workflow would be like..

    1. USA guy create a game and host it.
    2. USA game created sends a notification to the master server located in somewhere ( web host for example )
    3. Australian guy looks for hosted game.
    4. Australian game request a notification to the master server
    5. Master server says something like "hello australian, there's a game just created in USA, this is his ip, good luck, have fun!" lol

    works like that?
    this is really helping me to understand.. thank you!!

    best regads,
     
  7. PrimeDerektive

    PrimeDerektive

    Joined:
    Dec 13, 2009
    Posts:
    3,071
    Pretty much, yeah. The master server is just a list of servers that other players of your game are hosting on their own machines. Unity has a public one you can connect to and use for your game's matchmaking, or you can buy a web server and host your own master server.
     
  8. PrimeDerektive

    PrimeDerektive

    Joined:
    Dec 13, 2009
    Posts:
    3,071
    Not at all, this is just a tutorial and example project of a multiplayer game using Unity's built-in networking library. Photon has its own networking library, if you choose to use Photon, you have to do things their way.
     
  9. appels

    appels

    Joined:
    Jun 25, 2010
    Posts:
    2,685
    yeah allmost.
    when a client starts the game, a connection is made to the master server and the server will respond with a list of games available.
    the client then gets the option to join a game or host one.
    if he hosts one, the master server will add it to the list of available games and send that to all connected clients.
    the master server is a software that needs to run on a server thats reachable from the internet.
     
  10. zyndro

    zyndro

    Joined:
    Oct 19, 2010
    Posts:
    78
    Awesome explanation legend411 and appels!!! thank you a million!!!

    now i have it clear on my mind, so i can start working on this, it was hard trying to get something done if i havent and idea how it was working!!

    really appreciate the help!!

    @ legend411 Unity has one available? can you provide me more info about it please?


    best regards!
     
  11. PrimeDerektive

    PrimeDerektive

    Joined:
    Dec 13, 2009
    Posts:
    3,071
    If you bought this package (Leepo's Ultimate Unity Networking Project), any example project in the package using a master server is already using UT's public master server.
     
  12. zyndro

    zyndro

    Joined:
    Oct 19, 2010
    Posts:
    78

    ohhh i see.. then the Unity's master server available it's like a code structure.. i was thinking like a physical computer hardware server that was providing some kind of free hosting from Unity guys..

    my bad.. hehe

    ok, and then one last question.. it's kinda obvious but.. the game build must already contain the master server's ip in order to connect looking for created games or just to inform there's a new game created.. right? just to clarify..

    thanks again!
     
  13. Spectre9000

    Spectre9000

    Joined:
    Aug 30, 2010
    Posts:
    170
    @legend411

    How good is Unity's master server, and is it worth buying this product, or just waiting on Legion (which would seem to make this obsolete)?

    Also, I'm working on a MMO game on my own and I'm not a networking person so it's proving difficult (I have no time constraints so I can take it easy and work on it piece by piece, learning as I go, to get a basis up and running then I'll recruit for help once I've gotten all that up). I'm currently trying to use Photon as it's been promoted rather heavily recently and received a good bit of praise. I'm wondering though, as Photon is licensed per server, and for the free version I believe I can only have one license, I'm wondering if I should choose another. I'm currently thinking of having a Master server, a world server, a PvP server, and a dedicated database server to spread everything out and lessen the work load on server machines to provide better performance (correct me if I'm wrong with this way of thinking). Photon I don't think would allow this given its licensing, so I was wondering what your opinion on this would be seeming as you are fairly knowledgeable.
     
  14. cozza13

    cozza13

    Joined:
    Dec 13, 2010
    Posts:
    64
    Could anyone provide details on how to put the 3rd person construction worker in using the example code.
     
  15. PrimeDerektive

    PrimeDerektive

    Joined:
    Dec 13, 2009
    Posts:
    3,071
    actually you were right the first time. It is a public master server hosted by Unity Technologies. If you don't bother changing "MasterServer.ipAddress" in your project, it will default to use UT's.

    Yep. If you're hosting your own Master Server you just change MasterServer.ipAddress.

    The master server is just a piece of software meant to be used in conjunction with the built-in networking to store a list of currently hosted matches of your game. The actual matches are hosted by players on their own machines with their own ISP's, and therefore can only really support 8-32 players per server (unless someone has a T3 running to their house). For this purpose, it works great. Unity's built-in networking is really only designed for small-scale multiplayer games like this.

    Legion is designed for MMO's, and is a middleware solution just like all the other third-party networking packages out there (SmartFox, Badumna, uLink, Photon, ElectroServer etc). If I actually had to pick a third party networking solution, I would use uLink... unfortunately its $10,000 :( but it is awesome, very deeply integrated into Unity, and designed to be very similar in function to the built-in networking, which is very intuitive and user-friendly. The other packages I've tried are a bit more difficult to implement.

    Hardly :) I just love the built-in networking, and Leepo's product. appels and dreamora know a lot more about the nitty-gritty of networking than I do. (and Leepo of course)
     
    Last edited: Jul 5, 2011
  16. Spectre9000

    Spectre9000

    Joined:
    Aug 30, 2010
    Posts:
    170
    I'm trying to set up Photon right now as I'm wanted to set it up for an MMO as an authoritative server. It's proving... unintuitive at best... I'm also not a networking guy though...

    Legion I thought was supposed to be a unity extension to take over the current networking framework and connect specifically with Photon?
     
  17. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,670
    Spectre9000: If you are curious about other server middleware solutions, I have a comparison project in progress:
    http://forum.unity3d.com/threads/95277-Networking-Server-Comparison-Chart

    Just to reiterate, Unity Networking and Unity's Master Server are for games smaller than your average mmo. I would say the advantage of doing some work with Unity's networking would be to get a basic understanding of the nitty-gritty of networking. You seem to have a good over-view of large scale networking and how to lay it out (separate servers for separate parts to distribute load, etc...) but on the smaller "what do I do with this method" scale, doing a smaller game with Unity's networking might help that.
     
    Last edited: Jul 5, 2011
  18. PrimeDerektive

    PrimeDerektive

    Joined:
    Dec 13, 2009
    Posts:
    3,071
    Nope, not at all. Legion is to be an extension that interfaces between Unity and Photon to create MMO's easily. It's like, middle-middleware :)

    See here: http://forum.unity3d.com/threads/79809-LEGION-and-Photon

     
  19. zyndro

    zyndro

    Joined:
    Oct 19, 2010
    Posts:
    78
    guys and there's a specific IP address for this Unity Master Server?
    i was reading the Master Server documentation but i couldn't find that info.

    Thank you!
     
  20. PrimeDerektive

    PrimeDerektive

    Joined:
    Dec 13, 2009
    Posts:
    3,071
    There is, I actually don't know what it is... but if you don't change MasterServer.ipAddress it should be set to UT's master server by default. Just try Debug.Logging MasterServer.ipAddress to the console.
     
  21. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,670
    For my part... I'm still tracing wires...

    Partly because I need to for mobile development and partly because I want to know *why* and *how* the examples work, I'm translating these examples for use with EZGui. A lot of the code it deeply entwined with OnGUI and Update in ways that still confuse me, and I try to avoid these as much as possible when targeting mobiles.

    First off:

    Can someone explain to me, in Example 3 - GameLobby.cs, the logic around "lastRegTime"? Why is there "lastRegTime" and why, upon EnableLobby() it is set to Time.time - 3600? When lastRegTime is defined it's set to -60. Then it's checked and reset every frame in Update ();

    ... ... ...

    So, this is both a trap to detect when "enable lobby" is triggered by setting the clock back by a whole bunch AND a way to re-register an empty game every 60 seconds?

    If so: Why? I'm unclear why you'd need to constantly re-register an empty game...

    If not: What have I missed?

    Confused...
     
  22. zyndro

    zyndro

    Joined:
    Oct 19, 2010
    Posts:
    78
    awesome, i'll check it as soon as i get home.

    Thanks!
     
  23. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,670
    I notice that in GameLobby's "StartHost()" the call to MultiplayerFunctions.StartServer(blah) uses (players - 1) and later in OnServerInitialized() is sets maxPlayers to Network.maxConnections + 1.

    I've looked at http://unity3d.com/support/documentation/ScriptReference/Network.InitializeServer.html and I see "connections" is the "number of allowed incoming connections" but also docs state "number of players allowed in the game"

    Does "connections" include the host? Incoming connections *seems* like it could be number of players allowed in the game - 1 (the host), as the host is not "incoming"? This is implied by this code... is this the case?
     
  24. cozza13

    cozza13

    Joined:
    Dec 13, 2010
    Posts:
    64
    I am looking for someone to implement a character into the FPS demo that will sync walk run and jump animations. PM me if you are interested in the project.
     
  25. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,670
    Cozza13: I see that you've posted a few times, and I don't have the answer.

    If it were me, I'd use some sort of RPCs.

    Look at how you are controlling your character in a single player game. Do you have keys that make the character run? jump?

    Then you'd want to send that same information to the character on the other devices.

    At first I thought I'd suggest that you look at how Leepo moved the cubes and then follow that for the player transform, but then I realized you could get out of sync with your animations.

    I'd suggest sending animation flags via RPCs.

    You press <space> and you then have a local method that makes your character jump and sends an RPC to have the networked character jump.

    You press "w" and you then have a local method that makes your character run forward and sends an RPC to have the networked character run.

    This will need some prediction for potentially dropped packets AND you probably want to occasionally re-sync the transforms, but certainly in MMORPGs I've played, it's clear from seeing two side by side screens that the characters are not in perfect sync, but close enough for game play purposes.

    -

    Edit:

    Also - as this package is an example of Unity Networking, this is a perfectly legitimate question for the general Networking forum. This is as much an architecture issue as a Ultimate Networking/Leepo/M2H issue. It's not really related to this code base, per se, but really Unity Networking and Networking in general.
     
    Last edited: Jul 6, 2011
  26. cozza13

    cozza13

    Joined:
    Dec 13, 2010
    Posts:
    64
    @littleangel,

    Thanks for coming back to me on this. The above is the process that I was thinking I would need to go through, I was hoping that someone had maybe tried to do it with the 3rd person Controller and I could grab the code or if I could get someone to do it for me and then I would then share the code
     
  27. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,670
    Mmm... Makes sense. Eventually it would be great to see it as one of the examples, but I think we need some other updates first! (Manual Network View IDs?)

    Try posting this question on it's own and see who bites. You can also try the IRC channel:
    http://unity3d.com/support/community

    Under "Unity Chat".
     
  28. DerangedGames

    DerangedGames

    Joined:
    Mar 22, 2011
    Posts:
    1
    How does this compare with photon? I don't need more than 50 players per server so maybe I'm better off with this project?
    And has anyone got this to work with android?
     
  29. markis

    markis

    Joined:
    Oct 11, 2010
    Posts:
    51
    is it posible connect to sql?
     
  30. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,670
    This package is not a multiplayer middleware solution. This package is a tutorial and set of examples for Unity's built-in networking.

    Unity's built-in networking architecture is based on having a master server (one of which Unity Tech hosts as an instance for testing purposes) providing a game matching service between players, one of which must host the game on their computer. The expected connection limit is between 2 32, and is dependent upon the connection between the host and the client players. When a person chooses to host a game the master server adds adds the hosts game to a list of available games. When a player looks for a game to join, the master server sends the a list of available games and negotiates the connection between the host and players. The game is played exclusively on the computers supplied by the host and player. This is good for small to medium sized games. Arguably, this would be like playing half-life (CS, DoD) or similar games where you "look" for games on a list and choose one to join.

    Photon, SmartFox, Badumna, ElectroServer, etc.: all are heavy strong MMO packages. See my comparison chart (mentioned earlier) for an overview of what they can do. I'll be adding a column or Note about Unity's master server there soon to help clear up confusion.

    -

    Essentially what this package is offering is several tutorials and pre-made examples of Unity's built-in networking to jump start the developer in understanding Unity's networking, rather than relying on he basic Unity documentation.
     
  31. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    2,185
    I have to disagree with Little Angel: The external solutions are not heavy weight MMO solutions. This is not the best differentiation.

    Instead of using a Unity-client as host/server, most external solutions contain a dedicated server. While these are capable of running MMOs, most enable you to build room-based games as well. E.g. our "Lite" application is built around a limited number of players per room - but a big number of rooms running on a single server and it lets you achieve a lot without even touching the server code.

    A common drawback is that you will miss your scene's objects and the physics on the server. Physics calculations are computation intensive though and you might want to avoid to do these calculations for everyone. It will rise the cost per player (because of hosting costs).
     
  32. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,670
    Tobias: You are correct.

    I should have said:

    "Photon, SmartFox, Badumna, ElectroServer are dedicated server solutions that can handle, amongst other things, higher traffic than Unity's built-in networking, including in most cases MMOs."

    Unity's built-in networking is great for game matching smaller sized games using the master server.

    Unity's built-in networking can also act as a server when running in "headless" mode, but that is not covered in the Ultimate Networking Package.
     
  33. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,670
    Ok: I think I've figured out the answer to one question I've asked:


    This seems to be because the Master Server (loses track of? ignores? dumps?) registered servers relatively quickly. You can't simply register the host once and be happy it's still registered. This could be to keep a list of available servers that's as clean as possible. I can imaging that if someone stops hosting and hasn't written good clean-up code, the Master Server could still see this non-existant connection as valid.

    SO -

    This code forces a registration when the player connects by setting the "lastRegTime" to something ridiculously old, and the update loop re-registers the host once per minute.
     
  34. EvilDingo

    EvilDingo

    Joined:
    May 7, 2011
    Posts:
    189
    Bought this and tried it using Android. The FPS example just crashes after a few seconds regardless. There isn't anything obvious with the scripts. It dumps a mess of segment fault and hex when it crashes. The cube example works, so I wonder if it's just some voodoo with the FPS example only.
     
  35. MikeHergaarden

    MikeHergaarden

    Joined:
    Mar 9, 2008
    Posts:
    974
    LittleAngel:
    Yep, the Unity master server had a bug that it forgot registrations now and then, thats why its re-registerered now and then. I guess the bug is still around? Re-registering cant harm for sure, unless the masterserver is being spammed to death.


    maxConnections does not include the host. That's what the +1 is for, as in the GUI we want to show the amount of players playing (including the host)

    After this summer we'll probably go android ourselves, then I'll be able to test android as well.

    This could either be a Unitty android bug, full memory ..or otherwise.
    Where does it crash exactly? In the FPS main menu after a few seconds (doing nothing)?
     
  36. PrimeDerektive

    PrimeDerektive

    Joined:
    Dec 13, 2009
    Posts:
    3,071
    That's understandable, but whats the deal with the -3600 and -60 stuff? Could you add some comments into some of the master server logic maybe?
     
  37. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,670
    The -3600 and -60 stuff works, but it was quite cryptic. Update is checking to see if it's time to re-register the host by setting the lastRegTime to Time.time, and checking to see if the current time was longer ago (more long ago? all bad grammar) than the current time - 60 seconds "Is the last registered time older than the current time minus 60 seconds" or in other words: "Has it been 60 seconds since we last registered?".

    And then when you enable to the lobby, afaict, by setting lastRegTime to Time.time -3600 you are forcing the reregistration as it is DEFINITELY going to be older than Time.tim - 60.

    My explanation is seriously bad...

    In any case, once I realized what this was doing, I put this in a loop:

    Code (csharp):
    1.     void StartRegisteringHost () {
    2.         registeringHost = true;
    3.         StartCoroutine ("RegisterHost");
    4.     }
    5.    
    6.     void StopRegisteringHost () {
    7.         registeringHost = false;
    8.         StopCoroutine ("RegisterHost");
    9.     }
    10.    
    11.     IEnumerator RegisterHost () {
    12.         while (registeringHost) {
    13.             MultiplayerFunctions.SP.RegisterHost(serverName, "No description");
    14.             Debug.Log ("ReRegistering");
    15.             yield return new WaitForSeconds (30);
    16.         }
    17.     }
    The logic is a bit redundant, but hey...

    More comments and explanations throughout this tutorial would be fantastic.
     
  38. cozza13

    cozza13

    Joined:
    Dec 13, 2010
    Posts:
    64
    Hi,

    I want to change the GUI in the GUILayout of the multiplayermenu. Could anyone recommend a way to change it without having to dig into the code? Something that allows me to drag and drop, add a logo etc

    Chris
     
  39. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,670
    Chris,

    Not sure if there is a drag and drop solution, but:

    My normal "first suggestion" when working with Unity's OnGUI and GUI.x would be to change the skin, but I don't see a skin being used in the version of the MultiplayerMenu.cs from the Lobby Example (#3). That being said, this script in Ex.#3 is very short (67 lines), so you should be able to quickly modify it compared to some of the other scripts.
     
  40. LimeSplice

    LimeSplice

    Joined:
    Jul 15, 2011
    Posts:
    111
    Is this for iPhone/iPad/Android too or just windows/mac games?
     
  41. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,670
    LimeSplice: Leepo would know more about the intended targets, but I have a working implementation of Unity Networking based on code from this package and other sources that works on Mac, Web and iOS. I believe that there was one report of a game crashing when installed on Android.

    One should bear in mind that this package contains code and examples of Unity's built-in networking and is not a networking package in itself (like electro-server, photon, badumna, smartfox). You should look at this package as a tutorial with example code. That being said, the examples do seem to run "out of the box" and can be modified to fit your game.
     
  42. dlcl

    dlcl

    Joined:
    Oct 15, 2010
    Posts:
    33
    Hi all, I'm can't seem to get my Player to instantiate when the server initializes using a Tutorial 3 (authoritative) style networking for my third person game.

    The bit that (I believe) is completely stumping me is how Spawnplayer(Network.player) decides which prefab to spawn into the game. As in, it doesn't seem to reference any public variable that I can set in the inspector. Would anyone be able to enlighten me as to how Spawnplayer(Network.player) decides what to spawn, and where can I set the gameobject that I would like to spawn at this stage? Unfortunately, the Unity scripting reference page on Network.player isn't the most detailed. :(

    Here's the code I'm using (a modified version of Tutorial_3_Spawnscript):

    Code (csharp):
    1.  
    2. public class Tutorial_3_Spawnscript : MonoBehaviour
    3. {
    4.     public Transform playerPrefab;
    5.     public List<PlayerController> playerScripts = new List<PlayerController>();
    6.     public Transform playerSpawn;
    7.  
    8.     void OnServerInitialized()
    9.     {
    10.         //Spawn a player for the server itself
    11.         Spawnplayer(Network.player);
    12.         Debug.Log("spawned");
    13.     }
    14.  
    15.     void OnPlayerConnected(NetworkPlayer newPlayer)
    16.     {
    17.         //A player connected to me(the server), spawn a player for it:
    18.         Spawnplayer(newPlayer);
    19.     }
    20.  
    21.  
    22.     void Spawnplayer(NetworkPlayer newPlayer)
    23.     {
    24.         //Called on the server only
    25.  
    26.         //Instantiate a new object for this player, remember; the server is therefore the owner.
    27.         Transform myNewTrans = Network.Instantiate(playerPrefab, playerSpawn.position, playerSpawn.rotation, 0) as Transform;
    28.  
    29.         //Get the networkview of this new transform
    30.         NetworkView newObjectsNetworkview = myNewTrans.networkView;
    31.  
    32.         //Keep track of this new player so we can properly destroy it when required.
    33.         playerScripts.Add(myNewTrans.GetComponent<PlayerController>() as PlayerController);
    34.  
    35.         //Call an RPC on this new networkview, set the NetworkPlayer who controls this new player
    36.         newObjectsNetworkview.RPC("SetPlayer", RPCMode.AllBuffered, newPlayer);//Set it on the owner
    37.     }
    38.  
    The only changes that I've made to Leepo's code is replacing the reference to 'Tutorial_3_Playerscript' with my own 'PlayerController' script, and adding in a public Transform 'playerSpawn' variable so that the prefabs spawn at a specific point in the world.

    I've added a Debug.Log printout to the Spawnplayer(Network.player) line, but it doesn't print out when I test the game - that's why I have a hunch that this is the cause of my Player prefab not instantiating. I can still get a client to connect to the game and show up as 'Connected' with a ping display, etc., so I'm pretty sure the server *is* being initialized.

    Any insight into this issue would be much appreciated!

    (Sorry if the answer is obvious - I come from a design background and am just getting into C# :S )
     
  43. cozza13

    cozza13

    Joined:
    Dec 13, 2010
    Posts:
    64
    Has anyone had any experience using a proxy within the MultiplayerFunctions.cs? I am trying to connect out through a proxy and want to know if there is some script that I could use with MultiplayerFunctions.cs
     
  44. dlcl

    dlcl

    Joined:
    Oct 15, 2010
    Posts:
    33
    Aha, I've managed to solve the issue of my Player not spawning on OnServerInitialized() - I was already using OnServerInitialized() in a prior scene that loads the current level. Obviously as the server has already been initialized, that's why Spawnplayer(Network.player) never fired off.

    I've managed to get the server Player to spawn by moving the code to an Awake() function:

    Code (csharp):
    1.  
    2. void Awake()
    3.     {
    4.         //Spawn a player for the server itself
    5.     Spawnplayer(Network.player);
    6.     Debug.Log("Server player spawned");
    7.     }
    8.  
    9. void OnPlayerConnected(NetworkPlayer newPlayer)
    10.     {
    11.         //A player connected to me(the server), spawn a player for it:
    12.         Spawnplayer(newPlayer);
    13.     Debug.Log("Client player spawned");
    14.     }
    15.  
    16. void Spawnplayer(NetworkPlayer newPlayer)
    17.     {
    18.         //Called on the server only
    19.  
    20.         //Instantiate a new object for this player, remember; the server is therefore the owner.
    21.         Transform myNewTrans = Network.Instantiate(playerPrefab, playerSpawn.position, playerSpawn.rotation, 0) as Transform;
    22.     Debug.Log(" A Player instantiated");
    23.  
    ... but I'm now having an issue where 2 additional Players (instead of 1) end up spawning when a client joins. :(

    My Debug.Log checks only print out 1 instance each of a "Server player spawned" and "Client player spawned", as well as two printouts of "A Player instantiated". This seems to indicate that only 2 Players are being spawned.

    I'm wondering how the 3rd Player ends up spawning?
     
  45. dlcl

    dlcl

    Joined:
    Oct 15, 2010
    Posts:
    33
    Hmm, I still can't wrap my head around an authoritative server-client setup, even with Leepo's Tutorial 3 example, so I've decided to pare my ambition back a bit and am trying to use a non-authoritative setup, based on Tutorial_2B.

    I've managed to get everything to connect, however I'm having an issue of reversed camera controls when the client spawns in!

    I have a third person camera attached to the Player prefab - when the client instantiates, moving the client Player ends up moving the server Player, and vice versa.

    I haven't been able to make any headway using Tutorial_2B as a reference, as it only has one static Main Camera, whilst my setup has 1 camera per Player, attached to the each Player's model.

    This problem seems to be a little more straightforward than my previous issues. Would anyone have any helpful pointers as to what might be causing these reversed controls?
     
  46. hp94

    hp94

    Joined:
    Apr 1, 2011
    Posts:
    102
    For the people who have bought this, I have a few questions:

    On a scale of 1 to 10, how 'noob friendly' is it, 10 being the best?

    Does it explicitly handle being able to have one server that holds an account, characters, character information (ie position of last logout, 'stats', etc)?

    Does the authoritative server portion handle server shutdowns/startups/crashes without losing too much information (some is unavoidable, I understand)?

    If I have a few Windows machines available for hosting a game, and I wanted to have them become 'dedicated' servers, would I be able to have them reliably host the server? Is Smartfox necessary?
     
  47. mtewks

    mtewks

    Joined:
    Jun 10, 2011
    Posts:
    82
    Let's say I buy this and am working with a few others on a project. Will I be able to share the this product with the others or would they have to buy it as well?
     
  48. U7Games

    U7Games

    Joined:
    May 21, 2011
    Posts:
    943
    Hi!, i´m following the tutorial... thanks for this.. i´m having this problem in the tutorial 1 (the first one).. :

    "A client which was not in the connected player list disconnected. ???"

    that when the editor is used as a server and a standalone build is used as client..

    any ideas?
    thanks.
     
  49. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,670
    Mig-081: Seems you might have found a suggestion:
    http://forum.unity3d.com/threads/78800-Network-problem-when-building-the-game

    I have seen this a few times on my projects. When I search for this error string, most of the posts have projects that seem to be related to this package. I'm unclear what setting Application.runInBackground = true in Awake() will do if you've set that in player settings, as I assumed it was the same thing:

    http://unity3d.com/support/documentation/ScriptReference/Application-runInBackground.html
    "Should the player be running when the application is in the background?"

    http://unity3d.com/support/documentation/Components/class-PlayerSettings.html
    "Run in background Check this if you dont want to stop executing your game if it looses focus."
     
  50. appels

    appels

    Joined:
    Jun 25, 2010
    Posts:
    2,685
    it is exactly the same thing, you can set it in the editor or in code.