Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Collection of Multiplayer samples

Discussion in 'Multiplayer' started by seanr, Sep 17, 2015.

  1. seanr

    seanr

    Unity Technologies

    Joined:
    Sep 22, 2014
    Posts:
    669
  2. seanr

    seanr

    Unity Technologies

    Joined:
    Sep 22, 2014
    Posts:
    669
  3. GenaSG

    GenaSG

    Joined:
    Apr 19, 2014
    Posts:
    111
  4. asperatology

    asperatology

    Joined:
    Mar 10, 2015
    Posts:
    981
    I would like to contribute to this list but I can't seem to upload the project zip file here. Where else can I do so?
     
  5. GenaSG

    GenaSG

    Joined:
    Apr 19, 2014
    Posts:
    111
    You can upload your code to github.
    And share a link to the repository here.
     
  6. asperatology

    asperatology

    Joined:
    Mar 10, 2015
    Posts:
    981
    Here's the project link. This project shows how to make a non-player object as a player-controllable unit in a typical RTS application. (It's not a game, just an boring RTS sample of clicking here and there.)

    To test the project out, you need to first CTRL+B (Build) the project into a runnable executable, and then use the editor to connect to the runnable.

    Hopefully, it can help others out.
     
    Last edited: Sep 26, 2015
    Nikolasio and pKallv like this.
  7. asperatology

    asperatology

    Joined:
    Mar 10, 2015
    Posts:
    981
  8. Deleted User

    Deleted User

    Guest

    Last edited by a moderator: Sep 29, 2015
  9. asperatology

    asperatology

    Joined:
    Mar 10, 2015
    Posts:
    981
    New RTS sample project. This shows how to spawn non-player game objects from other non-player game objects. It may seem trivial to do, but just to get UNET working takes a lot of effort.
     
    Braza likes this.
  10. sfoust

    sfoust

    Joined:
    May 18, 2011
    Posts:
    26
    Update: A much cleaner version of a simple turn-based multiplayer Rock Paper Scissors game is now available below (my apologies to anyone who download the pile of garbage I posted earlier).

    Here is a simple turn-based example game of Rock Paper Scissors in two C# files (RPS_Player and RPS_Server) which are both components of a player prefab. (See attach RPS_10112015.unitypackage file below).

    This solution for a RPS game seems to work pretty well. But, I'm new to UNet (and networking in general) so I'm sure this is not the MOST elegant solution that could be created (feel free to post improve examples).

    This approach uses [ClientRpc] to sync data between player and player instance.

    Please have a look and please post better solutions.
    Critiques are much appreciated. :)

    Data Flow Diagram for RPS.png
     

    Attached Files:

    Last edited: Oct 13, 2015
    JoaoRFerreira, manthony_1 and Braza like this.
  11. Deleted User

    Deleted User

    Guest

    3 part series on UNET client-server communication, client-side prediction and server reconciliation, and quality of service channels. All parts contain a link to get a sample project that uses everything taught in the series.

    Part 1: http://www.gamasutra.com/blogs/Chri...torial_Part_1_of_3__Introducing_the_HLAPI.php
    Part 2: http://www.gamasutra.com/blogs/Chri...Side_Prediction_and_Server_Reconciliation.php
    Part 3 is in 6 parts:
    http://www.gamasutra.com/blogs/Chri...lation_Part_1_of_6__Break_Into_Components.php
     
    Last edited by a moderator: Apr 2, 2016
    seorge_ru and codestage like this.
  12. seanr

    seanr

    Unity Technologies

    Joined:
    Sep 22, 2014
    Posts:
    669
  13. seanr

    seanr

    Unity Technologies

    Joined:
    Sep 22, 2014
    Posts:
    669
  14. seanr

    seanr

    Unity Technologies

    Joined:
    Sep 22, 2014
    Posts:
    669
  15. seanr

    seanr

    Unity Technologies

    Joined:
    Sep 22, 2014
    Posts:
    669
  16. zKici

    zKici

    Joined:
    Feb 12, 2014
    Posts:
    438
    This is really a wonderful thread, thank you for keeping it updated. Lots of useful information.
     
  17. Kombiice

    Kombiice

    Joined:
    Jan 20, 2015
    Posts:
    64
    Yeah thats helpful
     
  18. Justice0Juic3

    Justice0Juic3

    Joined:
    Apr 29, 2013
    Posts:
    188
    Hi there.
    I'm kinda stucked right now. Regarding the Lobby-sample project, I can't seem to find the logic behind a team-selection. Can anybody please do some explaining?

    Or could you guys (the official UNet developers) come up with a sample project for this? :(
     
  19. asperatology

    asperatology

    Joined:
    Mar 10, 2015
    Posts:
    981
    The lobby example is the official sample.
     
  20. buzheteng

    buzheteng

    Joined:
    Feb 29, 2016
    Posts:
    4
    thanks for sharing~:p:p
     
  21. jamiejammas

    jamiejammas

    Joined:
    Aug 1, 2015
    Posts:
    1
    Are there any projects on here where an external computer can connect to a game someone is hosting without using unity's master server?
     
  22. asperatology

    asperatology

    Joined:
    Mar 10, 2015
    Posts:
    981
    Just connect via external IP address. No need for master server.
     
  23. Olipool

    Olipool

    Joined:
    Feb 8, 2015
    Posts:
    320
    http://bitbeast-games.com/wp-content/uploads/2016/06/SuperCars-Networking.zip

    Just wanted to add my sample project here. It evolved after following the networking tutorial in the manual. I adapted it to a 2D context and added more and more functionaliy I wanted to test out.
    It is a small car racer with a complete gameloop (getting ready, driving, show final standings), you can race against bots and other clients can connect anytime, replacing bots and if a player drops out a bot will take over his car. You can chat ingame and you can select a bot's car of your color and use it to block enemies or help them to the finish line :)
    It has some other not networking solutions as well, because I stumbled over them unexpectedly (driving a car above and below a bridge in a 2D context or programming a custom shader to colorize the cars for example). The graphics are taken from the old Amiga game Supercars and I hope in this context this will not cause any copyright issues.

    This is not the best code, it should be considered as a playground where you can test things out. It has evolved in that way so the class structure is a bit wild :) Also the networking code may not be what is considered as best practice, maybe there are even some faults, but I thought it could serve as a good starting point to see how certain things work together and as a playground to experiment in. It doesn't use any advanced features yet like client prediction, lag compensation etc. (at the moment the network transform just fires as often as possible).
    I added comments as well but if you have any questions feel free to ask. Also if you think the project has severe issues and is awefully implemented: please shoot as well. I'm eager to learn how to use UNet in the best way possible, especially handling collisions... :)
     
    Last edited: Jun 11, 2016
    errandfox, bingolino and notseanr like this.
  24. Nikolasio

    Nikolasio

    Joined:
    Dec 6, 2014
    Posts:
    59
    @asperatology Thank you very much!! Based on your sample projects I made a non player object with client authority draggable over the network.

    /*Still don't grasp it fully as I'm failing to identify the local player's non player object with a different sprite. I'm trying to swop the sprite in the OnStartLocalPlayer()...
    Any thoughts would be helpful.*/

    EDIT: I changed the color to differentiate between the players (sprite swop is also possible)

    Cheers,
    Nikola
     

    Attached Files:

    Last edited: Feb 28, 2017
    Synkrophosatron likes this.
  25. richard-lee

    richard-lee

    Unity Technologies

    Joined:
    Jul 14, 2015
    Posts:
    50
    Cross posting from Learn.

    https://forum.unity3d.com/threads/tanks-reference-project-for-unity-multiplayer-q-a.456783/

    Built on Unity's tutorials, Tanks!!! goes further, turning them into a live, fully featured, Multiplayer game. Get the game now, on iOS, Android, MacOS, or Windows. Then, get the source, available from the Asset Store!





    Tanks!!! Reference Project is a Unity Multiplayer project that is available for free on the Asset Store. If you’ve gone through the Multiplayer tutorials on our site, it should look familiar. It’s based on the existing Tanks! tutorials, but amped up into a fully featured game. This project includes code, assets, reference material… everything you need to build a the full game.

    We made this project because we’ve seen and gotten a lot of direct feedback regarding how one implements Multiplayer in a production environment. So, it demonstrates how to solve some common Multiplayer challenges like compensating for latency and cheating.

    Because this is architected as a production-ready game, it may be harder to digest than the existing Tanks! tutorials. So to ease people in, this project comes with a complete reference guide. You can also watch 3 part video walkthrough on Youtube right now.
    So, try out the game and then download it from the Asset Store. Then, let us know what you think on the Learn thread. I’m especially curious if this game really does help people understand Unity Multiplayer better and if we at Unity should create more “reference projects” like this one. PM me if you have detailed feedback.
     
  26. danreid70

    danreid70

    Joined:
    Aug 28, 2010
    Posts:
    225
    Definitely would love more example projects like this!!!
     
  27. Akki-bhatt

    Akki-bhatt

    Joined:
    Jul 8, 2017
    Posts:
    19
    This is also helpful.
     
  28. ZoidbergForPresident

    ZoidbergForPresident

    Joined:
    Dec 15, 2015
    Posts:
    157
    Would it be possible to have a simple project with either the low level api or the high level api but with server and client code separated?

    With very few features:
    - Clients connect to server
    - Clients can send a message to server
    - Server can send message to clients, specific or all

    ??? Been searching for weeks now and I did not find anything quite useable and simple (and working).
     
  29. ippdev

    ippdev

    Joined:
    Feb 7, 2010
    Posts:
    3,850
    I second this. The resources for this are all over the map and most not even less than a year old. If I want to integrate multiplayer networking I should not have to load a whole game...Tanks..and attempt to extract the simple parts i need. Like the fellow above..give me the basic working parts (that are effing current thank you) that are not game or app specific and let me get on with developing and making money. I simply need to pass the other players transforms around and implement chat and voice messaging and restrict users to specific lobbies. Really basic stuff you would think would be easily found. Maybe I am not googling properly..I don't know..but the fellow above has been looking for a few weeks which tells me my instincts are on the money. I do not need to shoot anybody. I do not need to have in app purchases. I do not need health bars. I do not need to use navmesh. I do need to decide between Photon and Unity. That decision is based on ease of implementation of chat, voice relay and reliable passing of CharacterController transforms. Any informed opinions out there or links to relevant up to date info are most certainly appreciated.
     
  30. ZoidbergForPresident

    ZoidbergForPresident

    Joined:
    Dec 15, 2015
    Posts:
    157
    Try this video:


    There isn't anything about lobby but I found it useable for simple messaing stuff. Transport layer got more understandable.
     
  31. ippdev

    ippdev

    Joined:
    Feb 7, 2010
    Posts:
    3,850
    This is great. I got up to the part where he connected server and client and I got no throughput. Did your try work as advertised? I do understand this much better and can hack through it at least.
     
  32. ZoidbergForPresident

    ZoidbergForPresident

    Joined:
    Dec 15, 2015
    Posts:
    157
    It's a bit jumbled at one time but I managed to make it work eventually.

    I can upload my scripts at least.

    Hopefully you'll manage to make it work too.
     

    Attached Files:

  33. ippdev

    ippdev

    Joined:
    Feb 7, 2010
    Posts:
    3,850
    I got them connecting. They aren't passing the Name stuff. I will take a look at your scripts in the morning. Thanks pal. I wish more tutorials were like this and just get down to brass tacks.
     
  34. Fortitude3D

    Fortitude3D

    Joined:
    Sep 7, 2017
    Posts:
    155
    Nice collection, thankyou!
     
  35. Ritesh_123

    Ritesh_123

    Joined:
    Dec 25, 2016
    Posts:
    1
    Hi I am working on a multiplayer quiz game but I'm not able to figure out how the things will work in multiplayer I am a bit noob in making multiplayer games. Also I am thinking of using Mirror for multiplayer a useful resource or a video can be helpful.
    Thank you