Multiplayer Game Architecture in Unity

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments

You can check out part 1 of my networking series here: https://www.youtube.com/watch?v=8VVgIjWBXks

Hope it comes in use!

πŸ‘οΈŽ︎ 5 πŸ‘€οΈŽ︎ u/ShrineWarsDev πŸ“…οΈŽ︎ Oct 05 2020 πŸ—«︎ replies

Saved! I'm excited to watch the rest of the series as it comes out :)

πŸ‘οΈŽ︎ 3 πŸ‘€οΈŽ︎ u/Xephorium πŸ“…οΈŽ︎ Oct 05 2020 πŸ—«︎ replies

Thank you so much for taking the time to produce this. Please continue this series, I know it’s going to be super valuable to the community. Look forward to seeing the rest!

πŸ‘οΈŽ︎ 2 πŸ‘€οΈŽ︎ u/SublimeBreeze πŸ“…οΈŽ︎ Oct 05 2020 πŸ—«︎ replies

Great work! Thank you.

πŸ‘οΈŽ︎ 2 πŸ‘€οΈŽ︎ u/gary23w πŸ“…οΈŽ︎ Oct 05 2020 πŸ—«︎ replies
Captions
in this video we'll go through an overview of everything you need to build a multiplayer game starting with the basic building blocks we'll look at the difference between several network topologies like local multiplayer lan peer-to-peer and dedicated servers after that we'll design the architecture for our own multiplayer game loosely based on fall guys and we'll look at the technologies available out there today throughout this series we'll build and deploy our own real-time multiplayer game similar to fall guys where up to 60 players can join a match and compete in various parkour challenges but first we need to understand the principles required to build something that complicated and that's what this is for we have a community discord server so definitely come hang out and feel free to ask any questions there alright so let's go over the basic building blocks of a typical multiplayer game at the lowest level we have a transport layer that is responsible for actually sending data the ones and zeroes that make up your game back and forth across the internet data is sent over the network for all sorts of things like synchronizing player movement attacks and animation health particle effects game state and so on it's the foundation for a multiplayer game on top of that are your game client and game server applications if you're using mirror both are built in unity but there are many games that use a separate application for the server anyways this involves all the additional code used to create the game simulation itself and manage the game state on the back end of a multiplayer game you have all the services powering the game so this includes things like matchmaking player authentication databases and third-party apis like steam or playfab finally we have our fleet of dedicated servers that are used to host games here we need to worry about things like scaling the fleet if there's a sudden surge of players how to manage updates and patches that we need to roll out and maintenance of a fleet to make sure that the servers are running 24 7 and as efficiently as possible back in the day you would have had to manage those servers yourself on premises but nowadays you'd be pretty crazy to not have your fleet in the cloud considering how much of a headache it is to maintain your own servers you also get a lot of amazing features and global distribution if you go with a cloud provider anyways when you look at a multiplayer game you can see that it's not really one specific program or application instead it's a distributed system that needs to be carefully designed and built in order to provide the best experience possible for the player let's take a look at some of the most common network topologies used for multiplayer games starting with local multiplayer local multiplayer which you might have heard referred to as couch multiplayer is by far the simplest to understand and the easiest to implement smash mario kart and several call of duty games are all examples of games with a local multiplayer mode these are games that can be played on the same machine on the same screen such as a tv if we look back at our building blocks the only thing involved here is the client application you don't even need to connect to the internet for these games so there's no need for the transport or the back end or the fleet the way you'd build a local multiplayer game is similar to the way you'd built any other single player game except you just have to handle inputs from more than one player there's many advantages to going with a local multiplayer game like the fact that there's literally zero latency because you've got no networking going on it's super simple and since you're not paying for bandwidth or servers there's also no additional cost associated with this topology the downsides are pretty obvious though you can only really have up to around four players per game as anymore would clutter your screen there's also the obvious in-person limitation here since you've got to be in the same place in order to play together land games are played in the same location on a local area network and they were really popular back in the day with games like quake and unreal tournament when online multiplayer was still in its early days lan parties are still a thing though and many games do have a land mode so it's definitely not obsolete as for our building blocks land games don't use the internet at all so the backend services and fleet aren't needed but since we need to connect multiple different devices there will be client and server applications built on top of a transport layer lan games come with many of the same advantages as local multiplayer games like minimal latency not zero because data is being transmitted across devices but since you're so close together the latency will be so small that for all practical purposes you can basically consider it to be about zero there's also no additional cost as we don't have back-end services to rely on nor fleet of dedicated servers but lan is more complex than local multiplayer implementation wise but in the big picture of things it's still relatively simple another benefit of lan is that you can have large games which is something you can't do with couch multiplayer the big downside with land though obviously is that you're limited to playing with people in the same location next up is peer-to-peer and this is where things start to get interesting when people say peer-to-peer in the context of games they're really referring to one of these two topologies the first one is direct peer-to-peer where every player is connected to every other player this is sort of the purest definition of peer-to-peer from a networking point of view while the other peer-to-peer topologies are really just client server in disguise direct peer-to-peer is cheap but it's a bit of a mess for multiplayer games as you have to deal with this huge data transfer web where each player communicates with everyone else and this can really complicate the implementation direct peer-to-peer also doesn't scale very well and there are also some security concerns because every player's ip address is exposed to everybody else in general i just wouldn't go with direct peer-to-peer i can't really think of a use case where you'd prefer this over player hosted client server which is next up so player hosted client server is what people really mean when they say peer-to-peer in this model one of the players runs both the client and the server applications and basically acts as a host this centralizes the traffic which significantly simplifies the implementation also if we look at our building blocks we'll need everything but the server fleet as we're using the players to host games this means we can really cheap out and save a lot of money but there are some pretty big problems with player hosted client server the first big issue is that everyone isn't treated fairly the host can have an advantage because they're running on zero latency and depending on how far apart everyone is some players might be totally screwed while others get lucky also what happens if the host rage quits or leaves the game either the game just drops or you have to deal with migrating the host which abruptly interrupts the game and again depending on where everyone is located it could totally ruin the experience for some players host migration is also really difficult to implement properly another problem with player hosted client server is cheating in this type of topology it's basically impossible to completely prevent the host from cheating since the server is running on their machine they can more or less do whatever they want to and there's very little you can do to stop them personally i would try to avoid player hosted games because of the bad user experience but there is a lot of money to save here so i understand why many games go this route last but definitely not least we have the dedicated server model in this model we control and manage the servers whether they're on-prem or in the cloud we can make the servers as powerful as we want we can choose how many servers we want and we can flexibly scale up or down our fleet we can also control where we want the servers to be located so that no matter where you play from you can have a great experience and since it's us not the players controlling the servers we can ensure a much greater level of security and reliability unfortunately in order to get these sweet sweet benefits we're gonna have to pay up since we also have to deploy manage and ensure our servers are running 24 7 we also have to deal with additional complexity but if you're looking to give players the best possible experience dedicated servers are one thousand percent the way to go now that we've covered the major network topologies used in multiplayer games let's look at what a sample multiplayer games actual architecture might look like for this i'm going to assume our game is similar to fall guys as we'll be building a game roughly inspired by fall guys later in the series so right away we can draw out some requirements we'll need to support up to 60 players per game just like the real fall guys we'll also need to make sure our system can handle real-time gameplay movement and physics we'll need various back-end systems like matchmaking a friendlift system and leaderboards we'll also need to store all kinds of player data like items skins achievements and stats lastly we'll also want to track some analytics things like engagement which translates to the daily active users or monthly active users retention growth revenue and so on okay now if we want to support up to 60 players per game with real-time movement and physics we're just gonna have to go with dedicated servers there's just no way we can have this be player hosted without the gameplay turning into absolute trash so we'll need a fleet of dedicated game servers how do we do this well we have plenty of great options if we choose to go with the cloud there is amazon game lift which is a dedicated game server hosting service that makes it pretty easy to deploy manage and scale servers on top of aws which is amazon's cloud platform there's also azure playfab which is by microsoft and their hosting service also makes it very easy to manage a dynamically scaled fleet of servers on their cloud service azure lastly there is the google cloud platform or gcp which also has a game server hosting service built on top of kubernetes which is a massively popular technology in the industry used to automate the deployment scaling and orchestration of clusters of servers there's many other platforms for game server hosting out there but these three are in my opinion by far the best based on functionality in the ecosystem and you can't really go wrong with any of them as for pricing it's very difficult to give you a precise cost because it depends on your needs but all three are more or less in the same ballpark player authentication is at the core of every multiplayer game nowadays players want the option to authenticate in a convenient and natural way and depending on the platform and distribution method you're aiming for you'll want to use the authentication provider that's most relevant for your game obviously you can still have the typical username and password or email and password as options but it's very common to allow players to link other accounts in my opinion playfab blows everything else out of the water they provide integrations with steam apple google facebook twitch and so on and you don't have to worry about managing authentication data or databases their api is really nice if you want to build a player authentication and identity service on your own that's also an option but do note that it'll be significantly more work matchmaking is probably the most complex part of a multiplayer game's backend so let's quickly go over what actually happens in the matchmaking process and then we'll talk about the best solutions available so when a player or a group of players wants to play together one player creates a matchmaking ticket and submits it to a matchmaking queue the matchmaking service is responsible for filling a match using these tickets based on a set of rules it'll also try to place you in a match offering the lowest latency so that players can enjoy a consistent gameplay experience once a potential match is made and accepted by all the players the matchmaking service will try to place the match on one of the servers in your fleet after that the matchmaking service will send a start request to a game server along with some additional data once the server receives that request it'll start up a new game session for the match and when it's ready to accept players it'll notify the matchmaking service once the game session is ready the matchmaker will update all of the players tickets with connection information and additional data and once that's relayed back to each player's client players will join the game hosted on the server and start playing so you can see this is a pretty complicated process and implementing a lot of this functionality can be extremely difficult on your own and that's why you should probably use an existing matchmaking service in my opinion the best game matchmaking services out there are flexmatch which is part of amazon gamelift playfab matchmaking and open match which is an open source matchmaking framework by google by now i know you're probably tired of hearing amazon microsoft and google over and over again but they really are doing a lot for multiplayer gaming anyways so our overall architecture will look something like this now where clients communicate both with the matchmaking service and with the authentication service as well as directly connecting to individual servers in our fleet when joining games now we'll need some sort of friendliest service to manage each player's list of friends as well as connect friends from their linked accounts from steam xbox playstation facebook or wherever else depending on what connected platforms you need you may have to stitch together a few different apis and build your own service or you can go with playfab's friendless service which is really nice and comes with all sorts of integrations in our architecture diagram we'll just group our friends in matchmaking services so we can sort of call this the service layer okay so leaderboards are similar to friend lists in that we can build our own but a simple way to start out would be either with the steamworks leaderboards api or again playfab's leaderboards api both are nice and simple to use although the steamworks api is obviously restricted to steam games only a quick side note is that for large aaa games there is a lot more involved here for example league of legends processes petabytes of data so their ranking systems are much more complicated both because of the scale but also because of the real-time requirements i believe their data warehouse architecture is built on aws so take from that what you will however any small to medium-sized game should be able to get away with using a simple third-party solution so we'll just go with that for now another core piece of multiplayer games is the need to manage persistent data like player items and purchases achievements statistics and so on to do this we'll need to use a database for our game we can use a simple sql database hosted on one of the major cloud platforms i'd recommend using a service like amazon aurora google's cloud sql or the azure database for postgres these are managed databases so a lot of the time-consuming and error-prone tasks are automated away for us like backups for example since we don't want game clients to directly query and interact with our database because of security issues we'll have a custom api layer deployed on simple virtual machines that provides us with game data from our database but in json format over http this gives us easier access and more control over our data and in the future we could even split these up into separate services each of the major cloud providers provides vms but i'll leave it at that since databases and apis are large topics in their own right and i don't want to go too in-depth here so for analytics my personal favorite is gameanalytics.com because its ease of use sample real-time multiplayer game later in this series i'll have videos dedicated to each part of this as we build our own multiplayer game roughly based on fall guys using unity and the mirror networking library anyways that's it for this video i did put a ton of effort into this one so i hope it comes in use for you but anyways i have our discord link below so definitely join that and come hang out and i'll see you next time thanks for watching
Info
Channel: Shrine
Views: 50,873
Rating: undefined out of 5
Keywords: unity multiplayer tutorial, unity devlog, unity networking, dev log, unity game devlog, unity 3d, unity mirror, unity multiplayer mirror, unity mirror networking, unreal networking, unreal multiplayer, multiplayer game backend, unity multiplayer devlog, unity game dev, unity 3d tutorial, game development, game dev, game development unity, unity indie devlog, devlog unity 3d, game dev log unity, unity multiplayer, unity game development, game devlog, game architecture
Id: 77vYKsXC4IE
Channel Id: undefined
Length: 15min 21sec (921 seconds)
Published: Sun Oct 04 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.