How to Package a Dedicated Server in Unreal Engine

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello everyone in this tutorial we will be going over how to set up your unreal engine project so that it can be packaged as a dedicated server then at the end of this video we will actually run the standalone package dedicated server and test it out locally by having clients connect to the server before we get started just want to give a huge shout out to all of our patrons on patreon as well as anyone who has ever donated the flop ram you guys truly help us create educational content and most importantly keep the content publicly available on youtube for free for anyone to watch at any time with all that said let's get started so first let's go over some prerequisites needed for this tutorial for instance you will need the source build version of unreal engine from github the epic games launcher version of unreal engine will not work because at the time of filming this video the epic games launcher version of unreal engine does not have the functionality to build projects as dedicated servers therefore if you don't have the source build version of unreal engine then please check out our other video which will be linked to the description below that covers how to download and build unreal engine from source the only other thing that i would recommend before continuing this video but is not necessary for following the tutorial is to better understand what a dedicated server actually is so we will have links in the description below to articles with more information on that and we may even make a separate video on this specific topic in the future if so we will be sure to link that in the description below as well all right now we can officially get started since you should have a source build version of unreal engine let's navigate to the directory where you put the unreal engine source built in using file explorer for me it's in my documents folder and i named that directory after the version of unreal engine that i'm currently using which is the latest version of unreal engine at the time of filming this video which is currently 4.26.1 and the reason why i'm here right now is that i want to create a new project through the unreal engine editor and for those who are unfamiliar with how to launch the source build version of the unreal engine editor open up the directory where unreal engine source is located then open up the engine folder then open up the binaries folder then from here open up the folder named after the platform that you are currently on and originally built the development editor configuration of unreal engine source 4 and visual studio for me i'm currently on a windows 64-bit operating system so i'm going to double-click the folder named win64 and from here scroll down and find the application named ue4 editor exactly and double-click that executable to launch the editor once the editor has opened up you should see the unreal engine project browser window like the one you see on my screen right now from here let's go ahead and make a new project so under where it says new project categories select where it says games then click on the button labeled next then for the template it shouldn't really matter which one you choose out of personal preference i'm going to choose the third person template and once you have your template selected click on next again now the only settings value on this page that has to be changed in my opinion to make things easier is whether or not the project is a blueprint or c plus plus project so please make sure to have c plus selected for this option label choose whether to create ace blueprint or c plus project now note that you can package a dedicated server build of a project containing blueprints it's just that the project needs some c plus plus source files so if you're following this tutorial with an existing project that doesn't have any c plus files in it then just make a new c plus plus class in your project using the unreal engine editor whatever values that you have for the other settings on this page should be okay but out of personal preference since it is kind of redundant i am going to change the starter content setting so that the project does not come with starter content because we are not going to use it anyway and lastly at the bottom here select the location for your project to be stored and name your project whatever you want for me i'm going to name this project tutorial project and once you have that done go ahead and create your project once unreal engine has finished creating your new project the project should have been automatically opened in the default code editor or ide associated with your source build of unreal engine so for example the project opened in visual studio for me if for whatever reason it didn't for you that's fine we're about to close out of visual studio momentarily but before we do i just want to quickly explain what we're going to do next and why so on the right side here in the solution explorer under the games folder and under the project name there's the source folder which will contain any relevancy plus plus and header files in her project but not just that it will also contain these two target.cs files so the question you may have is what are these files essentially these target.cs files define the settings used by the unreal engine build tool for specific build targets for your game project by default there's not going to be anything too interesting in these files unless you want to do something custom with regards to a specific build target if you are interested in what properties you can configure in these target files as well as what the different build targets are for unreal engine game projects we'll have a link in the description below to an article with more info on that so the most common build target that most people i believe are familiar with is the editor build target when you build your game to be played in the unreal engine editor the unreal build tool first looks at this file the editor.target.cs file to see how exactly the game should be built for the editor again there's nothing too special here as there are only a few lines in the constructor that basically say use the default settings for editor builds when building the game for the editor the other target.cs file which is normally named after the project's name is for the general game build target the general game build target is typically used by the unreal engine build tool for standalone games essentially this is the build target used when packaging the immersion of the game that is to be played outside of the unreal engine editor but the reason why i wanted to talk about this is that in order to build a dedicated server we need to define a server build target for our project which requires us to create a new target.cs file where the existing target.cs files are already located in the project source folder so let's close out of whatever code editor or ide that we were in and go back to file explorer but this time go to the directory where your project is located and open up your project folder and like we just talked about go to the source folder copy the editor.target.cs file and paste in this location then right click the newly pasted file select rename and we're going to name this target file tutorial project server.target.cs so for you guys watching it will be project nameserver.target.cs and then press enter when you are done after that we have to make some slight modifications to this server target file so go ahead and open this file in the text editor or ide of your choice it literally does not matter what you use you can even use notepad for this next step my default code editor for c-sharp files is visual studio so that's what will open for me as you can see right away we have to replace values pertaining to the editor build target with values pertaining to the server build target so first on line six and eight where it says tutorial project editor target let's replace both instances with tutorial project server target named after the file that we are currently editing and then on line 10 the build type is no longer editor it's server so just replace where it says editor here with server and that's pretty much it don't forget to save the file and we can now close out of this now in order for the unreal engine build tool to recognize this newly made server target for our project go back to file explorer specifically where the project's you project file is located right click that unreal engine project file and select generate visual studio project files after this completes the build tool will discover your server.target.cs file and we should be able to compile the project for the server configuration once the visual studio project files have been regenerated open the project in visual studio again by double clicking the project's visual studio solution file and once the project is open in visual studio go up here and click on this left most drop down menu so that we can change the solution configuration that we want to build a project for to a server configuration and here let's find and select where it says development server double check that the selected solution platform value in the next drop down menu to the right is correct and if it is then let's go ahead and build our project by right-clicking our project name right underneath the games folder in the solution explorer and selecting build once your project has finished compiling the development server build process should have been successful because we added that server target file which allows the unreal build tool to recognize the server build target now that we can properly build a server executable of our game let's move on to packaging our game as a server build so that it can be distributed to and run on whatever computer that will act as a dedicated server in order to do that we need to do it in the unreal engine editor but before opening our project in the unreal engine editor technically we have to build the project again for an editor build target because adding the server target file and regenerating the visual studio project files are changes to the project that require us to rebuild just the project so let's change the solution configuration of our build to development editor by selecting development editor in this drop down menu then go ahead and right click our project and select build again once your project has finished compiling once again let's go back to file explorer and open our project in the unreal engine editor by double clicking the u project file now that the project has opened up in unreal engine i just want to point out that again i am using the default third person example project which comes with one map which is the one you see right now the third person example map which will end up being for this tutorial the map used for the server build so when clients connect to the server they will see the map that we see right now but i'm just going to make a quick change in the project's default third person example map so since we are technically making a multiplayer game we don't need this default place mannequin in the map so i'm just going to select it and delete it the reason we don't need this is that when clients connect to the server a new mannequin pond will spawn for each client on the server and each client will get possession of its assigned pawn after that don't forget to save the changes made to your map and let's go ahead and create a new map that will represent what the client first sees when he or she loads up the game before connecting to the server you can create this map wherever you want i'm going to go into the maps folder in the third person cpp folder in the content folder of my project and right click here in the content browser and select level under where it says create basic asset and you can name it whatever i'm going to name it entry map then let's go ahead and open this newly created map and it's going to prompt you to save the content just go ahead and save it and you should see nothing but a black screen which is actually what i intended for this tutorial specifically i want to make this map as empty as possible because this is what the client will initially load before connecting to the server and loading the third person example map we just saw so there's only one change i want to make here in this map so if we play the game you will notice on the right side in the world outliner that there is now quite a bit of stuff and because this map is using the default game mode that came with the project that is used by any map in this project as you can see from the very last object down here let's change that so that the entry map is not using the same game mode that the third person example map is using so let's stop playing the game let's go to settings up here and then select world settings and by where it says game mode and to the right of game mode override click on this drop down menu and select either the game mode or game mode base option and save the map now when we play the game as you can see at the bottom of the world outliner we are no longer using the tutorial project game mode and just to show that this didn't affect anything else we can stop playing the game go back to the third person example map play the game here and if we scroll all the way to the bottom of the world outliner window you will see that it is still using the default game mode and you may be asking what is the point of doing this the reasoning behind this is that this will help better show later in the video the connection and transition process from a client map with no gameplay logic to a server map with a different game mode objects a character that takes in and responds to player input etc and that is all with regards to changes to the maps and you may be asking doesn't the entry map need some logic to connect to the server for this tutorial we will connect to the server by running an unreal engine console command from the client to once again better show the connection process in a easy and simple way while saving time so moving on let's make some slight changes in the project settings before modifying the packaging settings so stop playing the game go to edit and select project settings and we are going to be making changes to settings with regards to maps and mode so go ahead and select where it says maps and modes under where it says project on the left side of this project settings window now first under where it says default modes expand this section because we have to set the default server game mode to be the game mode that we want to be used by the map that we intend to run on the server which in this tutorial project is the third person example map which is running the default game mode the tutorial project game mode if you are not sure which game mode to use for the default server game mode just try to figure out which game mode is used when you play the server map in the editor moving on we have to set which map starts in a game slash client build versus which map starts in a server build so scroll down and expand the default map section and first let's change the game default map to entry map because like we talked about earlier we want the entry map to load when we launch a game build of this project on our client machine for the server default map changes to whatever map you want to run when we launch a server build of this project and what clients will simulate when they connect to the dedicated server in our case it's going to be the third person example map and that should be it for the maps and mode settings now we can go to the packaging settings which if you go to the left side here still under the project section and a little under the maps and modes section there should be a section labeled packaging so go ahead and click on that and let's scroll up now in here let's expand the packaging section within the packaging settings so that we can include all the maps that we need in our package build whether it's for a game bill the client bill the server build etc so let's scroll down to where it says list of maps to include in a packaged build and i'm just going to include both the entry map and the third person example map you can add an entry by clicking the plus button on the right here so let's click the button twice one entry for each map and then for each entry you will have to click on the three dots and that will open this little file explorer window where you have to navigate to find the maps you want to include in the package build the bare minimum needed for this tutorial is just going to be the entry map and the map to be run on the server and the only other change we have to make in the packaging settings not really a change but just to make sure is if we scroll down a little bit to the project section make sure that the build configuration is not shipping nor test in this video we are going to set the build configuration to development the reason why this matters is that like i said earlier for this tutorial we will connect to the server from the client using an unreal engine console command and as far as i know shipping builds do not have console commands enabled and test builds have only some not all console commands enabled and now we can go ahead and package our project so let's close out of this window go to file package project and first check the build target so for me by default the game build target is selected once again the game build will represent the client the player etc note that the order of whether the client or server gets built first does not matter we will build the server right after but for now let's package the client by selecting the platform you plan to run the game client on which for me is going to be windows so i'm going to click on windows and then this will open a mini file explorer window which will basically prompt you for where do you want to put this package build in now for me i'm just going to use the default location suggested to me which is basically my project directory so i'm going to go ahead and click select folder note it does not matter where you put the package builds in and then you'll see on the bottom right corner of the screen packaging project for windows and there's a small button labeled show output log i like to click on this um and then drag this window down here by the content browser in order to see the output log just in case the build fails for whatever reason once the game build has finished packaging let's package the server build so go back to file then package project and change the build target to the server target option then go back to file again then package project and select the platform of the machine that will run this decade game server in this tutorial we are going to run the server locally for testing purposes so i'm going to click on windows and i'm going to select the same location that i use for the client build and once again i want to see the output log just in case something goes wrong and i need to debug assuming both the game build and dedicated server build packaged successfully we can now finally test the server by running it locally and having clients connect to a local server so just really quickly if we go back to file explorer specifically in the directory of our unreal engine project or wherever you place those package builds the client build will be in this directory labeled windows no editor and the server bill will be in this directory labeled windows server where the word windows is interchangeable with whatever platform was selected for packaging first let's run the server so open up the windows server directory and in here you will see the executable that will run on the dedicated server now before we run this we are not going to run it by simply double clicking it here because we want to see the logs of the dedicated server and to do that you have to pass a log flag parameter to the application now there are plenty of ways to go about this but i personally prefer to do this in command prompt so let's open up command prompt and let's cd into that project's windows server directory by typing cd space and then copy and paste the path from file explorer into command prompt and press enter now that we are seated here let's run the server executable with the log flag parameter so go back to file explorer and look at the name of the unreal engine server application which should be the name of your project plus the word server go back to command prompt and just type that name out so in my case it's going to be tutorial project server and then dot exe space dash log and press enter and what should happen next is that you should see a new window pop-up representing your dedicated servers logs and now your dedicated server should be running locally in the background and if you look at the server logs you can see some information related to the server for example it's using the server game mode that we specified in the project settings it's running on localhost on port 777 since that is the default ip address and port to run on and our server map was loaded okay so since we know the ip address import to connect to let's run our project's game build so go back to file explorer specifically the location of the project's game build and since we don't need to pass in any flags this time we can just start the application here which should be named after your project by double-clicking it once the game has opened up and because we confirmed the entry map as the game default map all you should see right now in the game is a black screen and again this is why i said for this tutorial to not use a shipping or test spill because we are going to connect to the locally running dedicated server from our client using a console command so to bring up the console press the tick mark or tilde key on your keyboard on most keyboards that key is directly underneath the escape key and in this console we are going to run a command that will connect us to the server currently running on localhost so type out open and then space and you should see only one suggestion in this drop up menu and that is basically the command we're going to run so let's press tab to autofill and take in that suggestion and then press enter and that open 127.0.0.1 command should have taken us to the server map and basically i can move around i can do what i can normally do when i play in the server map in the unreal engine editor now if the command did not work meaning that your client is still on a black screen that means your server most likely fell asleep from being idle for too long due to not having a client connect in time if that happens then wake up the server by going to it you can press alt tab to get out of the client build and go to the log window for your server and just press enter a couple of times if that ever actually happens okay now for the real test let's get another client connected to the same server so let's go to where our client build is located in file explorer and let's launch another process of the client and do the same thing that we just did for the last client press the tilde or tick mark key and type that same command open 127.0.0.1 and press enter and just like when the last client joined the server we can move around and do everything that we would normally be able to do on this server map as if we were playing it in the unreal engine editor and if we go back to the server log you will notice that there were two join requests that both succeeded during the existence of the dedicated server so according to the logs both clients are currently in the same game and another obvious way to verify this is to have both clients side by side to see whether or not one client's pawn movement is being replicated to the other client screen to do this quickly i'm just going to move one of the player's pawns in front of the view of the other player's pawn and i'm going to jump and then press quickly press alt tab to switch to the other client to see that the other client's jump animation was indeed replicated by the server and once you're done testing let's shut down the server process by going to the server's log window and just in case the server is asleep press enter a couple of times and then press ctrl c and if you go back to either one of the client windows it should show the entry map again since the server kicked both clients out before exiting and that is pretty much it you have successfully built package and tested an unreal engine dedicated server if you enjoyed the video and found it helpful then please like comment and subscribe consider donating to us check out our other social media links all of that will be in the description below lastly huge shout out to our higher tier donors and patrons logicalcuber james for bowen jacobrand stumpy dwight everhart mitch small felix patterson mark wedge jimmy westcott morgan heidemann elise bioblaze payne lucas mosken rick morgan and solar tricks with all that said have a good day you
Info
Channel: Flopperam
Views: 11,545
Rating: undefined out of 5
Keywords: ue4, unreal engine, how to package ue4 proejct, dedicated game server, unreal engine dedicated server, how to build compile ue4 server, unreal engine build target, unreal engine local server, unreal engine game client, unreal engine multiplayer game, unreal engine fortnite, unreal engine 5, how to make a game with unreal, unreal engine source, ue4 replication, ue4 networking, ue4 client server model architecture, listen server, headless server, authoritative game server, p2p
Id: zNUxzl8Dcb4
Channel Id: undefined
Length: 23min 52sec (1432 seconds)
Published: Sun Feb 28 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.