hey there today I'm going to show you how to use unity's multiplayer dedicated server system in Matchmaker it's actually really easy to use there are a couple pitfalls that I ran into though I'll show you how to get past them and how you can have this up and running in just a few minutes we're going to use a very simple game so that way you can put in whatever game you want and it'll be really net code agnostic I'm using net code for game objects here but it would work with any net Code system the
whole point of this thing is to get servers up and running get players match made into different matches and games and then have them connect to those servers automatically you can do filters and all kinds of other interesting things but we're going to stick with the basics and I'm going to show you how you can easily get it working and have backfill working as well so that after your match has started players can keep joining in and keep filling up the game so that you don't have a server where you know the all the players
leave and then it slowly dies off there may be a lot of game scenarios where you want that though and you don't use backfill if you just want a match where everybody's pre-matched at the beginning and then at the end of it it's over kind of like a League of Legends or any team based type thing then you wouldn't want to do backfill so we'll worry about that right at the end let's start with the basics though now for my implementation of these Services of course I'm going to be using unity and I'm using 20
23.3 which will eventually get renamed into Unity 6 I believe and we need to install three packages there's the authentication package we're going to need and we're just going to use anonymous Authentication to log in for now so we have separate accounts for each player that logs in we need the Matchmaker package right here which is responsible for getting players together in cues and putting them into a pool and then sending them off to a server and then we need the multiplay package as well just for the dedicated server hosting side so once you have
all three of those installed let's take a look at what we'll need for a scene setup now the way that I like to do things is have a simple startup scene that my game can load into and then figure out what it needs to do from there in this startup scene I've got a simple startup script with the name of a client and server scene here I made this very flexible and very simple so when you download the code you can use it however you want and you can very easily see how everything is tied
together nothing really hidden here so let's open up the startup script you'll see here in the startup script I don't do much other than check to see if we have a command line argument where we're passing in a port if we are and just assume that we're the server otherwise we're the client there are a million different ways that you could do this check however you want to do it you just load into the correct scene and I load into either the server scene or the client scene and before we get too deep into code
and configuration on the dashboard let's take a look at these scenes first is the client scene the client scene just has a canvas with a little text object named status text absolutely nothing on it and you'll see that the code just looks for the only text object in the scene and then writes to it just to give us some little update and then we've got a client script with or a client object with a single client script on it the server is pretty similar it just has a server script and then here we have an
example server query Handler and this is actually from one of the unity samples that is pretty close to what I would say is easy to use but it had a a little bit of extra complicated stuff in there so I I ripped a little bit out and you'll see it but I wanted to leave the name in there not merge at all in there so that way you can see the bigger version just by going and looking at the example server query Handler that they have posted on the page now the last scene that we
have is the one that the players load into when they connect which is just level one it has a little button here to leave and then a text object and then it's got a plane on the ground so if I go into 3D mode you can see that it looks like a 3D World before we get into the complicated stuff of our clients and servers and how they all connect let's take a real quick view of the scenes so we have that startup scene and then on our clients we're going to have them load right
into the client scene so go into client and on the server we'll load into a server scene now when the client connects to the server the server or when the server starts up really it's going to load up level one and then that's going to be done with the network scene manager so that when the client connects they'll automatically load right into level one on the client scene they're going to go around and search so search for match I can't spell search but you get the idea and on the server they're just going to say
hey we're ready for a match and it'll tell the server system that it's ready and then take players and let's take a look at the flow real quick of how this all works and then we'll I think that'll make more sense before we jump into the code and again the config stuff which is really simple as long as you don't mess it up like I did the first time so here you can see you've got multiple clients and if I want to start a game my clients will first reach out to the Matchmaker the Matchmaker
will tell it or will look and wait until there are enough clients to start up a match so right now if my matchmaker says Hey games have to have at least two players to start then when one player connects it's just going to sit there and keep waiting and waiting and waiting and then as soon as a second player says hey I'd also like to join now there are enough players to get in it'll connect to the object or the server that's over there on Unity side that's doing allocations that'll spin up a new server
our game server and I'll show you how we'll set that up and how we'll upload that in just a moment it'll spin that server up though once that server is done it'll tell the Matchmaker that it's up and ready there's actually a call that we're going to make that says hey Matchmaker I'm ready for players the Matchmaker will then actually should probably turn this uh object around because it's kind of bidirectional tell the client hey go connect to the server it'll give it the server address and the IP and then the client will connect and
so will this client this one will get that same connection right there and then they'll be connected to the server and that's how it all ties together and if we set up the backfill of course then what'll happen is if client 3 comes in it'll go try to connect to the server one if we don't have backfill on though and this match is already started then client 3 would get sent over to the next server server two would get allocated and started up so again it's a lot of talking a lot of lines let's go
look at how it works now that we've examined the scenes let's take a quick look at our build settings because this is another part that could be very confusing if you haven't done it before when you're building a dedicated server build at least at the current time the servers only support Linux and realistically you usually want to use Linux because it's generally cheaper it tends to be about half the price to run a Linux server as it does a Windows Server primarily because of Licensing costs so you're going to want to do a Linux build
which means that you're going to need to have the build profile for Linux enabled this is the unity 202 3.3 version if you're in the older versions just go to find Linux and then you should see an option to install with Hub don't do Mac do Linux server or dedicated server is the option in the older versions in this one though it's just Linux server install that and then you're going to need to do a build now I'm going to show you the code that you'll build in a moment first I want to show you
the process I'll show you the code you can download it all and then upload it but to do a build just hit the build button and then I like to just create a sub folder off of my Project's folder named build and build into that so this is a multiplay SLU folder you see I've got my assets right there go into build I hit save and hit yes it's going to create a new build and it's going to deploy it out to that folder and in just a couple of seconds I'll get my Windows Explorer
window popping up it's probably a little bit different on a Mac but you get the general idea do a build and then we're going to set it up and deploy it into the dashboard there we go it actually just popped up and you can see it right here now let's go over to the unity dashboard here I'm in the gaming Services Matchmaker side and I've got a project named multiplay which is actually the name of the game server hosting or was the name of it it's getting renamed and changed around but that's just my project
name you can see my other projects right here starting with those some old 2018 ones huh and then over here on the left I've got the options for different things that I've been to before but if you just go to dashboard then you can find your project select your project and eventually get to your game server hosting section enable game server hosting and then the first thing you'll need to do is create a build so you go to the build section and you can see I've got one here named test I think that's a great
name for one I'm going to create a new one though named Test 2 because I can't have two of them with the same name so create a build and I'm going to name it Test 2 and we'll leave it as a Linux build because well one it's the only option and two like I said earlier it's drastically cheaper it's about half the price and we're going to leave it on direct file upload you can use these other options but direct file is pretty easy and I think probably the simplest there's also a deploy option although
I think it may only work from Mac I haven't been able to get it working on Windows yet that'll let you deploy straight from the editor so here we're going to choose folder upload and then we select that folder you see I've got that folder right here I just hit the upload button hit upload and then hit upload again and it's going to upload all of these different files so it's going to get all of the files in there and then figure out which ones are changed and replace the changed ones we'll see that happen
live right here just takes a moment and then we're going to be able to deploy out these Chang to all of our servers and have that happen automatically now I want to mention something real quick here when you want to make a new build like you have a new version of your game you do not create a new build here that I'm only doing this just to show the process so you can see how you step through and how you create it I've created that build that's cool and all but I actually don't need a
second build so I'm going to go back to builds select this one and delete it now to update a build you see here I have my build named test it's actually on version number 24 if I click on it I go to files and I go to update files here I can hit update existing files I can search again hit folder upload select that same folder and then it's going to allow me to upload those files to this build let's see as soon as it pops up there it is and then it's going to update
all of my servers that are running this build so don't think of a build as like a a build version or a build that you've released think of a build as more of a build configuration there's another thing called build configurations underneath so it's a little bit confusing and it's one of the things that caught me up the first time I saw it I wasn't really thinking straight about it and made two three builds and I was like wait a minute this this doesn't make sense we make one and we update it and it'll just
keep rolling out and you'll see how that works in just a second as soon as this finishes uploading I can hit next and then I've got an option here to either progressively roll out my builds so that when servers go down they'll come up with the new version but I don't kill them all or I can hit forced which will just kill off all of my running servers and force them to update right away I'm going to hit forc because I'm not in a live production environment even though my environment is named production once you
do that it's going to sit in a sinking state for probably a minute probably a lot more if you have a big project this is a relatively small one just to keep our times down and keep everything fast but we've got a build done we're next we're going to need a build configuration build configuration I've also named test because I just like to keep the name nice and simple and to build create a build configuration and do the same thing I'll just create one here name it test two you select your build so here you
just name your test and then you select your game server executable and if you just search for x86 there you go you should see this one the x86 64 that's the build for your Linux executable for your server leave this on sqp and then if you scroll down um I don't think you need to really change anything else everything else can stay default you hit next and then you can optionally add variables you don't need to do this either keeping it bare minimum going to hit finish and now you've got a build configuration again I
already have one so I'll just go find that one and I think I'm going to actually delete it and then we'll continue on with the next thing once you have a build configuration you need a fleet and a fleet is a set of servers or it's like a set of build configurations to server mappings let's show you what the settings are real quick we hit create Fleet we give it a name Test 2 it's still Linux we select our build configuration let's see oh apparently I can't do it right now CU I deleted that other
build configuration so I'll go create it again all right there we go I recreated it now it shows up in the list I hit test two and then I hit next and then it's going to ask me what region I want these servers to be in so I'll pick North America since that's where I'm at I'm going to set it at a minimum of one server and a maximum or actually I'll set it at a minimum of zero servers and a maximum of one which is a good number to have so that way if you're
not running anything you're not being buil for it set it down to zero now our Max servers is up at one but that doesn't mean it's our Max Games our server can run multiple game instances you see how that works in just a moment I'm going to hit next and then here there's our setting so servers per machine now this is going to vary based on your game depending on what your game requires my game could W with this game I could probably easily do 100 no it'd be pretty well I don't know about 100
but because the memory allowance per server would be a little H but let's go with like 20 so it's going to be relatively low um usage because I'm not sending much in my game as Tiny and this is going to scale with your game so you hit finish it'll create the fleet and then we go over to machines now when we're in the machines section if I just look right here and look I'm going to see that there's nothing there because everything is offline but when I actually start to use this thing it's going to
bring up servers and they they'll start to appear here so let's take a look at how we can spin up a server real quick that has a build with our current build and then we'll then we'll finally look at the code so you can see how that all works so here's our test allocation section if I go here I can create a test allocation I can select the fleet that I want I can select the region to put it into and the build configuration hit next and then hit run test what this will do is
kick up a server and start that dedicated server build that I just pushed over onto the server I'll show you how to look at that we'll see it running real quick and then we'll see the logs from it and then we'll see how all of this ties together with about 50 or so lines of code not counting debug probably less than that it's probably closer to to 30 lines of code not not counting all the debugs and just little curly braces so here we go we wait for the server allocation and that's going to take
a little while if you look over here at the machines section and here let's let's click away and click back so if I look at machines you see that it says None but I clear the online flag and you see that this new one is booting up once that finishes booting up then my test allocation here should start up and it should tell me whether or not my configuration is good and my build actually started this is a great way to just make sure that your build is working before you start trying to connect clients
make sure that all of the kind of server side stuff is up and working so let's double check it again if I go over here to my machines and clear that flag it switched to a waiting setup we'll give it just a second and as soon as it's ready we'll continue on all right it looks like our server up and running or the machine there and if I click over to the servers tab you should see that I've got one allocated and it's in my test two Fleet and I can actually click on that server
here I can click over to the files section and actually view the logs now your Unity log is going to be this engine. log and as long as it's not too big you can just click on it and actually view the data here so it says here that there's uh some missing prefab stuff but it looks like my servers starting up and listening and getting ready for some allocation stuff so let's take a look at code now let's start with the server side because I think that's where it's easiest to get confused you see I've
only got again four files here startup game player client server oh and then there's that one other one that we'll take a look at so let's go to the server file first in our server file if I scroll over to the correct part there we go you see that we've got a single field for the ticket ID this is for the backfill stuff we'll take a look at that later we're just going to look at start server first in the start method we kick off a co- routine for start server that is using the async
awaitable syntax you can use this instead of n numerator don't try to do an async void here because it ends up throwing some errors on the server side it's probably because it's a void instead of awaitable I don't know exactly the reason but kicking off a new co- routine here seems to make this work perfectly fine with all the Asing stuff again I still get mixed up in there oh I'm sure everybody else or some of you probably do too comment if you do anyway let's keep going so on line 24 we have a start
server method on line 26 we initialize Unity services this is a super common thing that you have to do for any of the service stuff that you want to use and then on line 27 I just grabbed the server config into a shorter variable so that we can set the transport connection data right down here without it being a giant long line so on line 28 we grabbed the transport from our network manager this is again using net code for game objects and I just set the connection data to be whatever Port multiplay has assigned
because this is running on the server it's running in multiplay Services again that was the name before now it's unity game server hosting or dedic I I don't know the name it's it it kind of influx I think but um this is the API call from the multiplay package that we got and it gives us the server config which has the port that way we know what port we're supposed to listen on and you need to make sure to set this IP address to 0000 0 not whatever the public IP address that you see is
the zero will make it bind to the local internal IP and then it's going to use that other IP as the external one that it's going to connect to after it gets routed through however it's getting routed on the server side after that I just log out a line for what our transport stuff is so that we can look at that in our debug log and see what it was it it should you don't really need it again most of the extra stuff here is just extra logs so you can kind of see the process
and flow as you're recreating this next online 32 if we're unable to start up as a server we do a little log throw an exception and then we're pretty much done the server is going to shut down and close itself out otherwise we set up some callbacks for client connection and server stopped and we just do a little bit of a log so that way we can see hey when the client connects or when the server stops inside that log that I just showed you a moment ago and then on 40 we load level one
using the network scene manager and this is again net code for game object specific thing just so that the server and client are in the same scene now let's get on to the dedicated server part which is actually right here on 43 first we have to set up a new callbacks event we're going to have to pass that into this subscribe down here on 55 the callbacks event has a couple different or it's an object that has a couple different events on it allocate deallocate error and subscription changed two of them we really care about
the other two we're going to just throw a log and ignore for now next on 49 and just wait until the multiplay service is actually ready and loaded up which it probably already is here but I just get a little bit paranoid and then I wait cuz I'm on the server and debug logging it stuff it's it's kind of a pain so wait a little bit here this is probably unnecessary the next part however is not on 55 we call the subscribe to server events async and pass in that call back method of course we
do need to await it and we get an object back but we don't actually need to use it for anything if we don't want to now let's take a look at the two important parts that I've mentioned there's the allocate and deallocate callbacks you look right here on 59 first I just do a little bit of a log just again so we can see it in the logs there cuz it's in the on the server side reading it from the log is kind of the only way to get it and then we have to call
this un well here let's look at allocate first on allocate on 68 we call ready server for players async and this tells the multiplay service hey we are now ready to start taking players so if you have something from the Matchmaker go ahead and send it over to us on deallocate just does the other the inverse of that and says hey we're no longer ready we're we're shutting down we're getting closed down um don't don't send us any more players and that's pretty much all we need for the server side without backfill happening we'll take
a look at backfill in a moment let's go look at the client side next here's our client script it's got a single field in it which is an initialized field and this again is probably not necessarily needed it's just there so that when we want to reuse a client just for our testing if we want to connect to a game and we want to leave and kick ourselves back to the client that we know that we've already logged in and run the initialized async stuff right here and our start method if you look here on
line 18 if we haven't initialized we call initialize async grab a random profile and then sign in anonymously this is just getting a random account so that everyone is signed into a different account if you sign in multiple players without changing the profile especially if you're in multiplayer play mode you're going to end up with a bunch of players that are all the same player and they won't be able to log in separately so you need to switch profile to something and at random is just nice easy way to do it and a mark initialized
is true again so that when we leave leave the game and come back to the client we don't rerun the initialization and then throw an error saying hey you're already signed in you don't need to initialize next we call start search though so we have this asynchronous start method and we're awaiting start search this part totally fine to run async straight from the start method works fine and it's all on the client easy to debug if something was going wrong so our start search method first creates a list of players and this is just a
list of player IDs that are going to be searching we're just going to search for the single player and not do like a group search that's trying to put multiple players in so we create a list of player entries and this is an object that comes with the Matchmaker and it has our player ID and then we can put in whatever custom data we want I don't want any we've got an attributes where we can put in some filters for the types of matches that we want to find don't care about those either and then
we've got a q name on line 37 on line 37 we I'm setting the Q name to test and then on 38 we create a create ticket options passing in that Q name and my empty attributes we could put in like rank filters and other things like that here if you wanted to next on line 40 we wait until we find a match if we haven't found a match we wait a second and then try again and we just keep looping until we find a match and we're passing in that list of players which is
again just our player and then the options and this is really just so that it can be a loop that goes on forever until we find an actual match now let's look at the find match method first thing it does is very lazily grab the transport should definitely be getting cashed somewhere and then it costs this create ticket async and this is going to create a ticket with the Matchmaker service with passing in those players and options saying hey I would like to join a game with whatever options I've selected here say hey I'd like
to join any game that's in that test queue now we'll do an infinite Loop here on 49 while true is just going to Loop until we break out of it we wait for 1 second do a little bit of a log saying the hey that we're doing a poll and what we're doing online 53 is polling the status of that ticket so we have our ticket response here this is the actual ticket that we've got we've got the ID of it right there and we just call get ticket async and pass in that ID it's
going to give us the status of that ticket whether it's been rejected timed out it failed or if it was found and successful next on 54 and just make sure that it is an assignment and cast it as one I don't think that's ever going to fail but just the way that I wrote it and then um on 57 I this is again another just to be very obvious this is not production code this is replace it with whatever you want to do here or comment out the logs we set some text on whatever the
first text element in the scene is which for me is just that one little status text saying what our response was and do the log there too and that's just so that if I do a bunch of client builds and I don't have a debug log I can just see it right up on there on the screen nice and simple and then we go through and based on the status we either do one of two things if we found a match then we'll start up our client and use the assignment info IP and Port so
this is where we're getting that IP and Port info back it's coming back in that assignment and again that was in that ticket responses value being cast as an assignment once we do that we should be able to just connect just like you do with any other connection and again if you're not using net code for game objects you just set your IP and Port here and do whatever you would do to start your connection then we do a little bit of a log saying that we started it and we add a log entry here
for connection events and I'm going to show you what this does in just a second it's really just logging when a player connects and disconnects how many players are there so that you can see what's going on and make sure that your whole workflow is going when you have a real game going with characters coming in obviously you probably won't need that you might do something else there though instead and the other thing that we do if we time out or fail is just do a little bit of log and return false remember if we
return false it's just going to loop back in so that's all the code there that we have for the client remember this is calling into the Matchmaker service and we haven't taken a look at that yet so let's go there now here's the Matchmaker service and this is what it looks like after you've done a bit of testing so you had lots of connection attempts and not a lot of matches and then eventually started kind of getting that leveled out and then did something weird here where I made a whole bunch of requests and uh
I think I sent them all at once really really quickly anyway the setup for this is pretty simple we have q's and q's have pools in them let's create a new queue here's my test queue you've already seen that one I'm going to create a test two CU and then it has a maximum number of players on the ticket so let's say I want maybe up to 10 players I think that was what I put for my Max right could be and then if I click on this oops let's see what it says it's invalid
and you see it says it requires a valid pool before matchmaking can begin so let's click on it and we'll go over to the pool section we have to create a new pool now the pool I'm going to name test two as well and then it's got the name test too and here I have to give it a timeout so this pool is a group that people will be querying into and they're going to um basically wait for however many seconds before they we send them a timeout that it to took too long now I
have mine set to 30 seconds I think that in a real production game you probably want to set this up to like 5 minutes or something so that people have lots of time to just sit there and wait and they can wait and wait and wait but when you're doing tests I feel like getting that shorter time is much better you can see what's going on you'll see lots of timeouts but that's fine you'll kind of get used to it and then crank it up so I would my recommendation to start at 30 seconds and
then adjust it afterwards once you've gotten used to it get the kind of core system working you know that it's working before you wait because you don't want to wait and wait and wait and wait and see if it times out for for five minutes so you hit next and then we choose our Fleet if I pick that new Fleet I can pick the new test configuration and the new and the region I hit next again and here I've got a Define are matches so for this I'm just going to name it test two as
well and here's where I think you could Define different types of matches like oneon-one three on three or um whatever type of thing you want freefor all you decide what type of match you want here you decide if you want backfill enabled or disabled and then you define your team so you have like team one or maybe I make this team FFA and my match definition is FFA and then the team count um well I would just leave that as two for the minimum two teams and maybe 10 as the Max and then for the
minimum player count two and 10 so that way we can have up to yeah that's right we have up to two teams or we start with at least two teams up to 10 teams that are all FFA ones and then we have um there we go one player per team up to 10 10 actually no up to one so there we go that would be one person per team with copies of them all it's very confusing I get mixed up and you can adjust it however you want but I'm going to go with this so
that I get two people in a team and I think in my other version I'll show you the other one I have them on the same team so I have one team count here let's do that one team with a minimum of two players and a maximum of 10 and a maximum of just that one team so this would be like a teamed up against the computer FFA or like 10 players versus PC or versus NPCs I hit create and it's I should say two to 10 players and that'll create my pool and get everything
ready so that's all I need to get the key part working next we've got to look at backfill and I want to show you this actually running in action show you kind of how it works or show you that it works all right let's watch it in action now so here I've got one instance from a build already running and we're going to start up seen I'm going to press play and it should go into this in progress view so that it's sitting there it's on the client there we go it's in progress waiting that's
the ticket status right there if we look right here at the code that's this online 56 response equals assignment. status and now it's just waiting for one of those replies either for it to time out or for it to uh connect or fail so we'll give it just a moment and if I pull up the dashboard I should be able to go over to my server section and I cleaned up that other instance let's go to clear the online filter and my there we go my one test Fleet now is booting up so it's going
to take a moment and I'm going to see it probably time out and fail first that's kind of what I should expect to see and you're going to see this whenever you haven't run your server for a while it's going to shut down again to save money you don't want to just keep running it constantly and it does take I don't know exactly the time but I would give it maybe up to 5 minutes to boot the first time once the server up and running though or the machine is up and running the servers come
up really fast because they're just Docker containers from what I can tell that are spinning up and they're really really quick to start up but the actual instance here take a second there you go you can see we actually timed out we hit that 30 seconds and if we give it just another few minutes we should be able to get there so let's pause the recording there we go we've moved ahead one step to a waiting setup and eventually it's going to be booted and then it's going to deploy oh look at that it looks
like it already happened so it connected and then it looks like we instantly disconnected let's go find the unity window yeah looks like it instantly disconnected I'm going to restart it real quick though which is Rerun our client probably a side effect of something else that I had done and then we relaunch my dedicated server bu or my not dedicated Ser build my other client build there we go in progress in progress it should start connecting them my expectation is that they will both connect in just a second so if I go over here to
servers I should see one's allocated there it's starting up and then it should connect these players and send them into it let's give it a second it's got the one on Port 9000 and the one on Port 9100 oh it looks like I failed again I think maybe my allocations were taken up let's see if I refresh I have it set to Max of two servers and it looks like that's the problem that it already has them set for somebody else so let's just stop here we go I'll show you what to do is I
just go over here go to my servers and find the oh it just restarted the new one there we go but I don't know why I disconnected okay oh I do know why I disconnected I've updated the server and the client and they're now out of sync so let's go take a look at that let's I think that's actually a great thing to show let's click on the server here and if I click on the files and I go to the engine log CU you're going to run into this at least if you're using net
code for game objects you see right down here where's it at oh this is the wrong one this is not the one that I connected to so this let's go back this is 677 what was the port 9,000 it should be this one oh it should should be that one files and log ah there it is I missed it the first time it's right up here at the top I'm totally blind but it was this that I was looking for Network config mismatch so that's why it didn't connect just because they were out of sync
so let me do a quick build but first let's take a look at the backfill thing then we'll do a build and wrap all of this up now before we go into the backfill stuff I just want to quickly mention that if you don't want back filling in your game like you've got a League of Legends Style game or something else where your teams stay the same from the beginning until the end then you can just use what you have now don't worry about this next part but if you want to be able to have
players come back in and rejoin games and stuff then this is important so check it out it's pretty simple once you get the flow working now there are a couple things to note here first right at the top we need to keep this server object around after we've started our game and jumped over to our level scene so we go into level one we need to make sure that the server object is round so we have a don't destroy onload here on line 20 this actually caught me off a couple times it happens when running
on the server and running in Linux don't realize that hey my server object got shut down because it got destroyed anyway let's continue on so we have our start server method that actually does do one thing for the back fill in line 21 we'll take a look at that in a second and then on line 22 we have this start Coe routine that kicks off and approval that's going to run every second let's take a look at the start server part if we go down to the bottom you see that right here on the end
of start server after we've kicked off in actual Network server we wait and we do that subscribe to server events async and then call this create backfill ticket let's hit F12 and go see what that looks like right down here you'll see that first we get the results from our multiplay service this is our matchmaking results and to do this you have to use the multiplay service get payload allocation from Json and use this matchmaking results type which is actually built into the Matchmaker Library you can see it right there and it was this was
one of the things that was a little bit difficult for me to figure out found it in some sample code though and then realized how it works so I assume that this payload can change and you can have different types of data in there if you want to customize it but this is the default that we've got here so we have our matchmaking results and then on line 87 and do a quick log just to show our connection stuff this property is actually I think just logs out the string or the type so it's not
very useful but it's nice to know what environment what the match ID is and we have to create a backfill properties where we patch pass in the match properties of that results and that's why we need to get this results object so we can pass this match properties in and we can hit F12 on it you can go look at all the the data for match properties if you want but I'm going to just kind of skip over it or gloss over it it's got our teams though our players that are in there the region
and our backfill ticket ID which is kind of what what we're going to need let's continue on on line 92 we have the name of our q and I just have it out here as a separate variable just to make it really obvious what this is so when you're looking at it just make sure that it matches your Q name and then a connection string which is just our IP address and Port it's not really a full connection string like in a typical programming. net way but it's just the port and or the ipn port
that we need to pass in to our options so we create a backfill ticket options here on 996 using that connection string some attributes where we could do filters that we're going to ignore for now and the backfill ticket properties next on line 103 we call this create backfill ticket async which is going to give us back a ticket ID which is a string that we'll be able to approve every second and you can see down here on line 106 I have a little countdown just um helping me debug log this you don't actually need
a countdown but if you want to see it kind of wait for the stuff to go you can have that in there you can cut that out the part that we actually need is really just a while loop that runs so something that's going to run indefinitely so while TR is just going to be true forever and keep running until we break out or the game ends or this object gets destroyed we wait for a second if we have a ticket ID then we continue on if we don't have one well if we don't have
one we continue the loop and go back and just write a little log if we do have one though we call this approved backfill ticket async method and pass in our ticket ID all of the rest of this is just logs you see like this entire thing could be shrunk down to about four lines you just have lots of logs in here so you can see what's going on when we run it now let's try it out to save some time I already did the build and deployment so it's going up there right now and
we'll just just wait for this server to come up as soon as our server boots up again we'll be able to try it out all right there we go our client's connected and I should be able to look at the log on our server real quick and see that it's looking for backfill so let's just go do a quick check scroll down here got our waiting and then it's approving backfills constantly looks good let's go try actually backfilling running another client so kick off another multiplay executable and we should expect this one to join in
and become client number three give him just a couple seconds couple more seconds go check the logs oh there we go they connected it took a second took a little bit longer than I expected from to get in but they did get in connected and joined as player 3 before I even got into the log there we go so back fill is working we've got our players connecting and uh hopefully this is useful for you and you're able to start building out your own dedicated server games again we're not covering the actual game part for
our game here got a simple little script on the player that just sends an RPC and I'll show you that real quick just for completeness so we've got our player prefab here and I'm going to make this whole project available for download too if you want to download this and try it out just run it yourself you be able to grab it I'll put a link down there in the description so you can go grab the entire thing and and try it out and just run it on your own just make sure that you set
up your own project ID of course you'll have to do that to make it all work here's the player though it just has a simple game player script on it that sends a test RPC I believe in start so yeah on and start if we're a client and we're the Lo local player we send a message to the server a server RPC that um then tells it to send a message back out to the client nothing complicated there at all again building your game part is pretty separate from building the server infrastructure matchmaking and setup
stuff and I wanted to really just kind of demystify and simplify this as much as possible so people can figure out all of the steps that kind of caught me offu guard while I was going through the process myself anyway if you have um thoughts about this or questions or comments please drop them down in the comments below I'm open to seeing what other types of stuff we can do here what things I may have missed or what things might be uh better or better explained and if you want to learn more about uh General
multiplayer game development make sure you check out the multiplayer Mastery course as well I'll link that down in the description or you go to game. courses slmp all right thanks again don't forget to thumbs up subscribe and all that stuff and I'll see you in the next video