Search Unity

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

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

  1. duhprey

    duhprey

    Joined:
    Nov 13, 2009
    Posts:
    165
    The technique I use is similar to legend411, except that when I do the network destory (without a buffered rpc) I call RemoveRPCsInGroup to get rid of the instantiate on new connections. In addition I set the group onall networkviews attached to that object so that any of its associated buffered rpcs are destroyed along with it. Of course, this works well because I only have one object per player :)

    I think it's the case that the destroy only works on rpcs originating from that player despite having matching group numbers.
     
  2. PrimeDerektive

    PrimeDerektive

    Joined:
    Dec 13, 2009
    Posts:
    3,071
    You mean the RemoveRPCsInGroup? Or Network.Destroy?

    Also, given what you just said about doing RemoveRPCsInGroup when you network.destroy a disconnecting client's playerprefab, I'm assuming you have all players' prefabs in seperate groups then? (otherwise you'd be removing the instantiate rpc's for the players that are still in the game, right?)
     
  3. duhprey

    duhprey

    Joined:
    Nov 13, 2009
    Posts:
    165
    That's right, currently each client is in a separate group (max 32 players) what I'm curious about (when I said destroy I meant RemoveRPCsInGroup) is whether I can reuse the numbers safely between players because the network debug message seems to imply that it's only removing rpcs in the group that belong to that player. In which case I could use this for more players and on more than one object per player.
     
  4. ddesmond

    ddesmond

    Joined:
    Feb 9, 2010
    Posts:
    150
    Hello,

    I imported the package and am getting the following error:

    Assets/Standard Assets/Scripts/FPSWalker.js(10,21): BCE0005: Unknown identifier: 'FPSChat'.

    Can you shed some light on this?
     
  5. ddesmond

    ddesmond

    Joined:
    Feb 9, 2010
    Posts:
    150
    I found the problem, some of the sample scenes have the same script names of other scripts, so I had to comment the conflicting ones out for now. You may want to consider having unique names.
     
  6. MikeHergaarden

    MikeHergaarden

    Joined:
    Mar 9, 2008
    Posts:
    974
    Hm, I i reimport the entire project I get no compile errors. Could it be that you moved some scripts or imported the assets in a project with conflicting files? (e.g. my old 2.X tutorial project)
     
  7. ddesmond

    ddesmond

    Joined:
    Feb 9, 2010
    Posts:
    150
    I guess in my demo project, I have lots of projects. Some projects have different names for commonly used scripts like mouselook etc... Can't wait to tryout out, thanks for the quick response.
     
  8. MikeHergaarden

    MikeHergaarden

    Joined:
    Mar 9, 2008
    Posts:
    974
    Aah No I see, it conflicted with the Standard Assets? I should fix that indeed. I'll rename the projects assets.
     
  9. ddesmond

    ddesmond

    Joined:
    Feb 9, 2010
    Posts:
    150
    Thanks
     
  10. PrimeDerektive

    PrimeDerektive

    Joined:
    Dec 13, 2009
    Posts:
    3,071
    Are you sure about this? I was under the impression that RemoveRPCs(Network.Player) does remove Network.Instantiates for that player.

    Did you try doing it with a groups, and using RemoveRPCs(Network.Player, groupId)?
     
  11. Scorch

    Scorch

    Joined:
    Jan 12, 2011
    Posts:
    20
    Yes, everything was set to group zero.
     
  12. PrimeDerektive

    PrimeDerektive

    Joined:
    Dec 13, 2009
    Posts:
    3,071
    Hmm, that's strange. According to this exchange between between JohnGalt and larus, RemoveRPCs(Network.Player) should remove network.instantiate calls from the buffer for that player.
     
  13. naoufal

    naoufal

    Joined:
    Feb 9, 2011
    Posts:
    1
    Where can I get Project!!!!.?????

    and tutorail !!!!plz


     
  14. PrimeDerektive

    PrimeDerektive

    Joined:
    Dec 13, 2009
    Posts:
    3,071
    Its on the asset store. You have to buy it.
     
  15. Leonsito

    Leonsito

    Joined:
    May 21, 2010
    Posts:
    23
    Bought this yesterday, what can I say... FANTASTIC WORK !

    It feels like I can do whatever I want now regarding networking in Unity.

    Thanks for making it public, for the amount of knowledge you get I think it has a very fair price :)
     
  16. MikeHergaarden

    MikeHergaarden

    Joined:
    Mar 9, 2008
    Posts:
    974
    Thanks, I'm glad you enjoy it! Good luck with your projects
     
  17. Scorch

    Scorch

    Joined:
    Jan 12, 2011
    Posts:
    20
    This is definitely worth the purchase if you are evaluating various network choices. There are lots of examples you can likely find whatever it is you need to get started. Thanks again for your help Leepo!
     
  18. agentsmith

    agentsmith

    Joined:
    May 1, 2010
    Posts:
    132
    Is the nat/punchthrough bug fixed with Unity 3.2.x?
     
  19. MikeHergaarden

    MikeHergaarden

    Joined:
    Mar 9, 2008
    Posts:
    974
    Yes, 3.2 improves nat punchtrough and has some other nice fixes. You can now also properly remove an instantiation call, which was a point of discussion here :).
     
  20. agentsmith

    agentsmith

    Joined:
    May 1, 2010
    Posts:
    132
    When you say improves, does that mean the bug is gone? I wanted to a have a browser based game that people can host and others can see it and join in (like you did in your crash game). I ran a small test and I thought I saw the "limited" nat punchthrough message with 3.2 but in 2.6 it ran just fine.
     
    Last edited: Feb 11, 2011
  21. MikeHergaarden

    MikeHergaarden

    Joined:
    Mar 9, 2008
    Posts:
    974
    The connection status testing had been improved, so it could be it now gives you a different result indeed. However, if that now also means you are now unable to connect between two clients that could easily connect before that's a problem.

    I know of any open unity networking bugs atm though :). (Only features that are by design...which could be changed for the better)
     
  22. agentsmith

    agentsmith

    Joined:
    May 1, 2010
    Posts:
    132
  23. BigB

    BigB

    Joined:
    Oct 16, 2008
    Posts:
    656
    I think the project broke with the update to unity 3.2.., mono behaviour missing everywhere.
     
  24. MikeHergaarden

    MikeHergaarden

    Joined:
    Mar 9, 2008
    Posts:
    974
    It does work here and I received no similar reports, please try reimporting again or try reimporting in a different/empty project. It must be something else.
     
  25. GFX47

    GFX47

    Joined:
    Dec 7, 2010
    Posts:
    115
    Hi there,

    I've just discovered UNP via Asset Store and all this looks pretty cool.
    I have a little question concerning the content of tutorials and code samples: does it treat data interpolation/extrapolation and prediction through network?
     
  26. Crowe T. Robot

    Crowe T. Robot

    Joined:
    Jan 30, 2011
    Posts:
    28
    I don't believe these tutorials really cover a lot on the Extrapolation / interpolation... but that doesn't mean they're not excellent.

    I used Leepo's tut to get the infrastructure kind of set up, and then took a look at Unity's NetworkRigidbody example code, and used that example to frame my CSP stuff.
     
  27. GFX47

    GFX47

    Joined:
    Dec 7, 2010
    Posts:
    115
    Don't get me wrong, that's not what I'm saying :)
    I'll get it anyway, just wanted to know how deep this was going.
     
  28. MikeHergaarden

    MikeHergaarden

    Joined:
    Mar 9, 2008
    Posts:
    974
    It's mentioned quickly, but not covered in depth. I point to the Unity example on this subject.
     
  29. Oracolo

    Oracolo

    Joined:
    Feb 16, 2011
    Posts:
    2
    Your networking project is very interesting and usefull, but I'm encountering a problem compiling the Example n.2
    Compiler says:

    Assets/M2HNetworking/Example2/C#/MultiplayerMenu2.cs(14,9): error CS0103: The name 'GameSettings' does not exists in the current context

    The problem is that the class file GameSettings.cs does not exists in the whole project.
    Any suggestion?
     
  30. MikeHergaarden

    MikeHergaarden

    Joined:
    Mar 9, 2008
    Posts:
    974
    Please try reimporting the package again. GameSettings.cs should be under Plugins folder. Next to MultiplayerFunctions.cs (you can verify this in the asset store file tree preview)
    Maybe even try importing the package in a new project.
     
  31. Burke

    Burke

    Joined:
    Feb 7, 2010
    Posts:
    15
    Hi Leepo, do you have any examples of connecting from a LimitedNATPunchthroughSymmetric to a PortRestricted Host with the client using a Proxy. I would buy it to see that example.

    Also, do you use Network.Instantiate and Destroy, or do you use a real system for pooling objects to avoid garbage collection artifacts?
     
  32. shadowfork

    shadowfork

    Joined:
    Jan 8, 2010
    Posts:
    164
    Quick question,

    will I be able to use this on iOS devices?
     
  33. MikeHergaarden

    MikeHergaarden

    Joined:
    Mar 9, 2008
    Posts:
    974
    I dont think I can properly include an example as you need to run a proxy server, it's dead simple though: Install the Unity proxy server and then have clients (or the server) use the proxy.

    The tutorial shows all methods to instantiate (manually or using network.instantiate). But personally I avoid network.instantiate and have my own manual instantiation and cleanup. This is discussed and shown in the project.

    The tutorials etc you'll do on your PC/Mac, but the networkign can be deployed to iOS indeed, you need Unity pro though.
     
  34. shadowfork

    shadowfork

    Joined:
    Jan 8, 2010
    Posts:
    164
    Awesome! I do have the pro version.

    Will you be considering adding documentation to integrate it to iOS devices anytime soon?

    Thanks!
     
  35. MikeHergaarden

    MikeHergaarden

    Joined:
    Mar 9, 2008
    Posts:
    974
    Unity networking works exactly the same on iOS AFAIK.
    There was something with having to do some web calls to keep wifi active, but I believe these networking issues have been fixed by the new 'keep WIFI active' setting.

    So unless iOS required extra work to get networking running I don't think it needs any extra documentation. But it might be worth it to simply add a small section that clearly states that it all works out of the box :p (plus the WIFI tip).
    I'll be releasing crashdrive (with multiplayer) on iOS soon so I'll be able to verify that everything works.
     
  36. Oracolo

    Oracolo

    Joined:
    Feb 16, 2011
    Posts:
    2
    Got latest version.
    Now all is compiling fine. Thank you.
     
  37. falkonragno

    falkonragno

    Joined:
    May 31, 2010
    Posts:
    29
    Hello Leepo, I think this is an amazing product, but I'm interesting in create a game for Facebook, would you add maybe in a near future an example for this, I not good programming I'm an artist but I been learning a lot from people like you, please let me know I'm thinking buying it, thanks.
     
  38. univtydev0008

    univtydev0008

    Joined:
    Jan 19, 2011
    Posts:
    41
    Hey Leepo,

    First of all i would like to thank you for putting this together, as it has help me tremendously. However i am having troubles with the example 3 lobby system...when i use the C# scripts it does not function properly, such as it does not update the players in the room or in chat and chat is not working at all...also one thing i noticed is when the game is launched out of the lobby it doesnt remove it from the server list. Again thanks for your help and any further help with these issues would be great as i really need a Lobby system for my upcoming game!
     
  39. Vimalakirti

    Vimalakirti

    Joined:
    Oct 12, 2009
    Posts:
    755
    Re: Lobby

    C# lobby chat worked fine for me, and fine overall. The server list updated when the page was refreshed.
     
  40. wilcoco

    wilcoco

    Joined:
    Feb 22, 2011
    Posts:
    2
    I have been following your tutorial..
    but i encountered following error message at tutorial 2a1

    "Assets/M2HNetworking/Tutorial 4/C#/Tutorial_4_GameManager.cs(29,25): warning CS0414: The private field `Tutorial_2_GameManager.localPlayerInfo' is assigned but its value is never used

    How can I fix this..?
     
  41. MikeHergaarden

    MikeHergaarden

    Joined:
    Mar 9, 2008
    Posts:
    974
    wilcoco: Ah it's just a warning. You -could- ignore it. However I myself also hate having warnings around.
    I believe you can simply remove that variable. It's not used..only assigned once.

    I'll fix this in the official package as well.
     
  42. wilcoco

    wilcoco

    Joined:
    Feb 22, 2011
    Posts:
    2
    As you metioned.. there is no side effect.. It works well...
    Thank you for your real time customer service.
    Very Impressive !!


     
  43. univtydev0008

    univtydev0008

    Joined:
    Jan 19, 2011
    Posts:
    41
    Im not sure whats going on with mine then as i have reimported a fresh package in a new empty project and simply swapped all the JS to C# and am still gettin the weird behaviour.

    http://img412.imageshack.us/i/m2htutorial.jpg/



    This is a screenshot of me running the webplayer two times and testing.

    As you can see on the Server(left) it states that 0/4 people are connected, and the chat verifies that the client(right) has connected to the server. Also in this neither player is able to chat and the server cannot launch the game. As stated before I have reimported this package numerous times and new projects each time and still get the same behaviours.

    Also note that it works perfect in JS.

    Thanks again for your time and sorry for any inconvienence..
     
    Last edited: Feb 22, 2011
  44. MikeHergaarden

    MikeHergaarden

    Joined:
    Mar 9, 2008
    Posts:
    974
  45. univtydev0008

    univtydev0008

    Joined:
    Jan 19, 2011
    Posts:
    41
    Hey Leepo,

    Sorry for all the confusion, I have solved the problem and it was rather silly on my part as it was early when I did this. The problem was when I put the C# scripts on the Code gameobject I simply disabled the JS scripts, I just noticed this and removed the JS scripts entriely and it works perfect!

    Again sorry for the confusion, my bad =P and thanks a ton for your work man this was well worth the money!

    EDIT: There still seems to be one problem which is the server list not updating. When the player starts the server it does not remove it from the list of servers even after refreshing the list several times and the client can still connect to the server which locks them into the lobby of the game. Also even after the server is closed it still shows up in the list. Note that it does seem to update if the client refreshes the entire web browser and starts the game over. Please help =D
     
    Last edited: Feb 24, 2011
  46. MikeHergaarden

    MikeHergaarden

    Joined:
    Mar 9, 2008
    Posts:
    974
    Hm right. theres two problems to solve there:

    1.After the server moves to game state it should set it's maxconnecions to -1
    Besides that the UnregisterHost call should be succesfully called.

    EDIT: Weird, this is already done
     
  47. tikod

    tikod

    Joined:
    Nov 30, 2010
    Posts:
    19
    Someone know if this tutorial explain how to install,run use a master server on debian?
     
  48. MikeHergaarden

    MikeHergaarden

    Joined:
    Mar 9, 2008
    Posts:
    974
  49. tikod

    tikod

    Joined:
    Nov 30, 2010
    Posts:
    19
    Ok, I build and run this. (MasterServer Facilitator). I'll try to connect with this script :

    Network.Connect("myDebianlIP", 23466);

    On my server i see : -INFO- New connection establisehd to ...

    But in Unity i never receive any message. I have to modify file of master server and build a new version?
     
  50. HiPPiE1337

    HiPPiE1337

    Joined:
    Feb 13, 2011
    Posts:
    7
    Wow nice tutorial. Unfortunately i cant buy it :(.
    But i have some questions: whats improved in the zero to hero guide fps example.
    And what are the extras in your network class?
    Is the zero to hero guide compatible with 3.2?
    My last question: is the zero to hero guide good for beginners?
    ---------------
    Offtopic: you come from netherlands ? Me too, can i pm you in dutch with questions i get later?