Search Unity

  1. Unity 2019.2 is now released.
    Dismiss Notice

Dedicated Server Using Unity Multiplayer

Discussion in 'Connected Games' started by Aimlessone, Mar 1, 2017.

  1. Aimlessone

    Aimlessone

    Joined:
    Jun 26, 2015
    Posts:
    46
    I have a game I have been working on that I want to be multiplayer, but when it comes to multiplayer aspects my knowledge is limited. All of my very little experience is working with the Unity Multiplayer. Using the client host to host a local game for testing purposes with my team is perfectly acceptable, but I would eventually like to host this on a dedicated server to allows multiple people to be playing simultaneously in different game sessions as well as track wins/losses and rank.



    I haven’t found but a few threads on the possibility of this, so I was hoping to get some direction or someone point me to some documentation that explains if this is possible and how I would go about doing so.
     
  2. donnysobonny

    donnysobonny

    Joined:
    Jan 24, 2013
    Posts:
    208
    Well, in that case, welcome to the mad world of network programming!

    So a few things to get you started:
    • some one-size-fits-all solutions (such as the HLAPI part of unet (unity's networking) and third party solutions such as Photon's PUN or Thunder service) will make this easiest for you, in converting your current single-player game to multiplayer. Note however, since you talk about preparing for the future, that these types of solutions can only take you so far. They are "convenience" solutions, making it as quick and easy to make a multiplayer game as is possible, at the cost of performance. As you'll find out later on, maintaining server costs for multiplayer games is expensive, so keeping your solution as lean as possible is highly recommended. I'll talk about this more shortly.
    • you mention a "client to host a local game", which is in fact the "peer-hosted" model, where one player acts as both a player and the server, and all other players act as players. This is the cheapest setup, because it means that you'll have zero expenses, but it is by far the most error-prone setup. It's very difficult to get this right.

      You already mention that you are interested in a more dedicated approach. Going from peer-hosted to something like the client-server model would be a bit of a nightmare so I suggest to start off with a better solution: the client-server model. This is ultimately where all players are clients, connecting to a single server that you host yourself. I can give plenty of advice on how to go about setting up this sort of a setup so if you need more info, let me know. Unet is designed to be used with the client-server model too, so you should find it pretty easy to get started with this.

    Convenience vs performance

    So anyone who has been doing this for any length of time will tell you to focus on performance, in which case you would likely need to consider a re-structure of your code. However, there is validity in the convenience approach. Network programming is a complex beast, so if you just want to learn and/or get started, you might find it easier to start off with something like the HLAPI/PUN/Photon thunder, and get your head around the various concepts related to networking. So ultimately it depends on how much you want to future-proof yourself right now.

    No doubt you'll have plenty of questions, so feel free to ask away and i'll do my best to advise.
     
    Kushovu likes this.
  3. Aimlessone

    Aimlessone

    Joined:
    Jun 26, 2015
    Posts:
    46
    Thanks for responding donnysobonny,



    Yes, soooo many questions. But I will try to keep them relevant to where I am at this point. I have walked through a few tutorials from Unity on their networking solution. To convert what I have to multiplayer it looks like I will need to be changing/adding code anyway, so restructuring it for performance at that time will need to happen as well. As for peer-hosted, that is what we do now to test the game with more than one person. What I am looking to ultimately accomplish is a matchmaking system that matches players based on some variable I have yet to come up with or implement.



    If accomplishing that is possible with a client-server model, then I am all for it. I just don’t have the knowledge here to know what is capable in each model. I understand that I will need to learn quite a bit here on my own and I am fine with that. I am just looking for some direction on where to start so I don’t put valuable time and effort into a direction and realize down the road when I am more knowledgeable that I chose the wrong path months ago.
     
  4. novabyte

    novabyte

    Joined:
    Feb 27, 2015
    Posts:
    11
    Hi @Aimlessone. It's a great answer from @donnysobonny but I want to understand better what you have in mind for multiplayer. There's a few different kinds of multiplayer you can implement for your game - which you choose really depends on the gameplay experience you want (although anti-cheat affects the decision as well).

    Which multiplayer do you want in your game?
    1. Realtime multiplayer with client/server. Sometimes known as realtime authoritative multiplayer.
    2. Realtime multiplayer with client as server (via a "host"). Used in lots of FPS games because it's cheap but complicated to get right.
    3. Realtime multiplayer which has no host. All peers are equal and each client receives messages and adjusts it's local game state as needed. There's no way to trust messages so this has the biggest risk or re-sync the client with some "server" host as in 2 above.
    4. Asynchronous multiplayer. Like with Turn-based games. No live socket connections. Think Words with Friends from Zynga as an example. A player can close the client and come back to pickup from where they left off.
    There's also a lot of cross-over hybrid multiplayer solutions which fit bits of both above. If it's easiest just describe the type of game you want to build as multiplayer. :)
     
  5. donnysobonny

    donnysobonny

    Joined:
    Jan 24, 2013
    Posts:
    208
    Hmm okay, matchmaking is a tricky challenge on it's own, so I would definitely recommend a pre-built solution for something like this. Unity's own HLAPI does come with some third-party services such as their matchmaking system, so that might be a good place to start. I would be cautious though. The small amount of time that I've spent personally with unity's matchmaking/relay servers and other third party services has made it fairly clear that they aren't particularly great (likely because they are free!).

    I'd maybe suggest to take a look at Photon Thunder. It's ultimately unet, with the matchmaking and other third party solutions managed by ExitGames (the guys that make photon). It will obviously cost you more to use something like this, than to either use unity's lesser-quality third party services or make your own, however my experience with ExitGames services (although a bit dated now...) is that they are good quality, as is the support.

    It would also be possible for you to venture into your own custom matchmaking solution. If you are confident in your abilities, and have experience with databases etc, I would highly recommend this. Be aware though that matchmaking can get very complicated, very fast. So if in doubt, i'd stick with a pre-built solution for this one.


    Let me know if you have further questions.
     
  6. Aimlessone

    Aimlessone

    Joined:
    Jun 26, 2015
    Posts:
    46
    @novabyte

    I would say option 1 through 3, haha. My game is real-time, it’s an arena battle game. Think of the Tanks game used in the Unet walkthrough or a game like Battlerite if you heard of it. Again, I’m limited in knowledge of network but it is a fast paced game so I would assume that I would need one of those.



    If I remember correctly, Halo two used something similar to option 2. But I remember using the modem standby in that game to cheat a bit. I could force a 10 second lag where they’d be stuck in place but I could move. So long as I didn’t timeout and pass the host to someone else, when I turned standby off it would sync them to where I was. Essentially I could run into a room, grab the flag, and run out and they’d be lagged the whole time. So it seems that system could work but might have some setbacks



    @donnysobonny

    I was hoping to use a pre-built system to make things as easy as possible since this is my first swing at things. What really matters is where the quality issues are. If it has issues with 2-3 games going then it will be a problem, however if that level can run smoothly then it should be fine for at least now.



    I have looked at Photon a bit (their free version) What I like about Unet however, is that it is documented very well and has a ton of resources for me to learn it. I’m sure Photon does as well but I haven’t really found anything. I also would like to stick to something that I don’t have to pay for until I know I’ve got a game and it’s functionality working the way I want it to. But that may not be possible.



    I actually know quite a bit about databases as I work with, design, and code the entire scheduling, shipping, and payroll databases at work. But with everything else involved here, I think a pre-built solution is the answer.
     
  7. donnysobonny

    donnysobonny

    Joined:
    Jan 24, 2013
    Posts:
    208
    Okay so, there's quite a bit of variance between what is involved in these two games.The Tanks example is obviously a simple peer hosted example (since this is the easiest thing to set up as you already know, but it's not particularly practical). Battlerite (awesome game!) on the other hand is actually very complex. I obviously don't know the exact setup that they use, but just from playing it myself, it's fairly clear that it uses a client-server model, where their server architecture spawns server instances to handle games.

    Now, stunlock have been around for a while, so I highly doubt they are using the HLAPI, or any third party solution. We know they've built quite a few multiplayer games so the chances are they have built their own solution. With that being said, everything that happens in battlerite is possible with unet's HLAPI, using the matchmaking system to match up players, and the relay servers to host matches.

    So if you're looking for a free-for-now solution to learn and gain experience, the HLAPI is definitely a good option, but just remember that it will only take you so far.

    This unfortunately is not true. They have been working on this alot, however, at the moment the only "good" documentation is the stuff to help get you started. Beyond that, documentation is currently almost non-existent. Even more so if you want to stray away from the pre-built features and roll your own (or use the LLAPI, which is very lacking in documentation).

    With that being said, I'd say to dive right in and give it a go, and if you have any questions, ask them in here.
     
  8. Aimlessone

    Aimlessone

    Joined:
    Jun 26, 2015
    Posts:
    46
    Haha, yeah I suppose there is a massive variance between those two games, so maybe that wasn’t the best example. I was just trying to help you visualize what I am trying to accomplish. Looks like Client-server is the right way to go here. As you may have noticed I have only gone through the get started stuff with Unet, which is why I probably have the false impression of good documentation. IF Photon can achieve the same result with better documentation perhaps it would be better to go that route.



    In my research of Photon is seems that they have the ability to convert any existing Unet architecture into theirs. I think the quote was something like “90% complete on import” or something like that. So perhaps I’ll start with Unet and see what I can achieve with that. If changes need to be made down the road I can manage that.



    Yes, Battlerite is an awesome game! Rook, Ashka, and Oldur are my go-to!



    Anyway, time to dive in! I really appreciate the help. I’ll come back here if I run into any questions.
     
  9. angusmf

    angusmf

    Joined:
    Jan 19, 2015
    Posts:
    247
    HLAPI is perfectly capable of "Client-Server". You simply start a server instead of a host, which is a server and client in one process. But you have a lot of infrastructure to come up with when you go that route. Something still has to launch that server process and advertise its address to your clients. There are a few convenience items in HLAPI that become less convenient when you have more than 2 players (distinguishing between clients and addressing them individually is not what HLAPI is about) but that doesn't get easier with other networking solutions that I've explored. (Note, I have not bothered with Photon or any other cloud-dependent services as I would like the option to roll my own or not require public internet.)

    Accessible infrastructure (self-hosted, cheap, whatever) is what's lacking, and leaves you with Photon or Unity's service which are aimed at peer-hosting in HLAPI. It's not a Unet or HLAPI problem. Gamesparks looks very interesting for this type of work, as do some assets on the store. Search for terms like "server" and "framework" for examples.
     
    Last edited: Mar 2, 2017
  10. donnysobonny

    donnysobonny

    Joined:
    Jan 24, 2013
    Posts:
    208
    If you are considering photon, I would recommend firing a quick post into their forum. The team are pretty active in there, and that will help you get some further advice on which of their services may best suit you (and allow you to gauge their level of support). If you're not happy with the responses from them, you always have the HLAPI to fall back on, and this forum to help you with any challenges you might face in using it.

    PUN, one of Photon's older and more well known products was based on that, from what I remember. It was based on unity's old networking though (which was very different to what it is now). Photon Thunder though is based on the new unet. From what I can tell (and don't quote me on this), it looks like photon thunder just tweaks the location of the services that you use. For example, when using the matchmaking services, it likely just points the requests to the photon servers, rather than unity's own. There's likely more going on under the hood than this but by the looks of things you'd be using unet's HLAPI as-is, along with photon's own services. They will surely clarify this further though...

    Yeah Rook is a boss! I pretty much suck with everyone else. Not sure we're even allowed to do this on here, but add me if you're up for a game: donnypwnz

    +1 on @angusmf 's input, some very useful points!
     
  11. GameSparks_Clare

    GameSparks_Clare

    Joined:
    Feb 7, 2017
    Posts:
    37
    Hi Aimlessone,

    If you’d like to look into using GameSparks, our customer solutions experts would be more than happy to jump on a call to discuss your requirements - you can get in touch with them via https://support.gamesparks.net/support/home

    Clare
     
    Allsaveone likes this.
  12. wizycatdesigns

    wizycatdesigns

    Joined:
    May 17, 2018
    Posts:
    5
    meh gawd some adervitising company on a forums
     
    Aimlessone likes this.
  13. codboygr

    codboygr

    Joined:
    Dec 3, 2018
    Posts:
    1
    Hey sorry to re-open such an old thread, but currently is there a way of using Unet with dedicated servers? I got really confused with all the answers and I'm simply looking for a yes or no. If it's a yes are there any tutorials worth watching or reading to help me implement this? Also, I'd like to avoid any 3rd party solutions, like Photon, Gamesparks etc. What I am looking for is a server to act as the client server model like you mentioned. Currently I am using the peer-hosted model and it's working, but I was asked to change that to the client server model.
     
  14. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    5,954
    Yes. From the HLAPI you just call NetworkManager.StartServer() instead of StartHost() or StartClient().
    Unet was largely abandoned by Unity about 3 years ago in a buggy and unfinished state, and was officially deprecated a full year ago. They have already begun purging Unet documentation and tutorials, so your best bet is to find some 3rd party tutorials on Youtube from 2016 or earlier.
    I'd recommend switching to a 3rd party network API unless your game is already just about done. But if you're still figuring out the server architecture, I'm guessing you're still pretty early on in the development.