UE5 Setting up Local Multiplayer / MP#1

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
okay hi folks here I am giving you a tutorial about how to create local multiplayer and Unreal Engine 5. now I've been having a lot of issues with a few versions of unreal and so I want to let you know this tutorial is built in 5.0.3 I've had issues with controllers and the use of controllers in the versions of unreal since 5.03 and I believe they are now resolved in 5.3 so if you are having problems with this tutorial try doing it in 5.0 .3 or try it in 5.3 unfortunately there was a break in the code I guess and they didn't get around to fixing it until 5.3 I'll be checking it in 5.3 since that's the new version of the engine and making sure that everything works fine but let me know if you have any problems as well okay so the first thing that I'm going to do is I'm going to play test and in order to do this tutorial I have my mouse and keyboard that allow me to control the player as normal and then I also have an Xbox controller that's plugged in and that Xbox controller is going to control the same player as well now the first thing that I'm going to do is I'm going to duplicate control D or command D on the Mac the player start and move it over a little bit that is going to allow me so that when I press play I still only have one but when I do another step it I can spawn a second player at this second location and I will be able to see it on my screen so to do that I'm going to go to open level blueprint that opens on another window for me so I'm just going to drag it in and once I have it dragged in I am going to right click and say begin event play pretty typical standing standard script nodule node excuse me for when we want something to occur when the game starts there we go I'm going to drag that off and I'm going to ask it to create local player and when we create local player we're going to leave controller ID set to negative 1 which is going to allow it to just keep creating and essentially fill the last spot that hasn't been filled with a controller and we're going to leave spawn player controller checked because this means that the player is going to take possession immediately that it's going to spawn now if you leave this unchecked that's for like when you have a player joining a game and they're going to join the next map or the next level on load okay I can now compile this and if I move this off to the side if I do a play test I now have two players that are spawning the one in the center is the one that I'm controlling and when I click in up above and I start moving you can see the one in the center of the top window I'm controlling and when I use the Xbox controller I'm still controlling the same character so by default the first controller and the mouse and keyboard control the first player the intention here is if you're going to have multiplayer you're typically going to have more than one controller which isn't the case for me or for this tutorial so to get around that we go to edit project settings and that is going to open up this window and buried in here if I just search for skip under local multiplayer is something called skip assigning Gamepad to player one this if I check it should mean that player 2 can be controlled by the GamePad if you have problems with this it might be your version of unreal they broke this in unreal 5.1 and it was not fixed until 5.3 let's try playing this again there we go that is the mouse and that is the controller fantastic we now have local multiplayer but what if you want to have a game where you have a single person playing and when someone else wants to join they can push the start button well that's what we're going to take a look at next let me bring in my scripting window again and I'm going to move this over a little bit and I am going to set this up so that we're going to utilize a variable to check if we have a player so I'm going to say variable and I'm going to insert P to spawn so this is player to spawn it's a Boolean so it's either true or false so that means that when I set it to true that there is a player in there and when there isn't a player it will be false I am going to right click in here and I'm going to create a new action for game pad special and Gamepad special great and I'm going to move this over here I'm going to replace event begin play with Gamepad special right so when you press that button it is going to create a new player I can break my old node Connection by holding alt and clicking and I can also select and just hit delete so now if I compile this and test it I have full first person playing and when I hit the start button on the controller the character is going to spawn at one of the open spawn points now that's an interesting point here let's redo that so here I am standing in one of the spawn points so when the controller hits I have to click in the window to activate the window then when I click the special Gamepad button the start button on the xpad it automatically generates player 2 I have control of player two and player 2 spawns in any of the open player starts so the difference here is if I move off this player start and then I hit start it could happen at the one that I started in it could happen in a different one it could happen at any of the player starts now one of the other things that I could do here is if you wanted to have more than two players this is going to involve going a little bit backwards but let's take these two let's duplicate them and let's rotate them so that they're all sort of looking into the center let's bring this back and say Bring Back event begin play and what I could do is I could have this repeat essentially just duplicating this I could make a loop but this is going to be faster okay so we get four windows and we get four characters in those four windows each one being controlled ideally by a different controller in this case I don't have those different controllers and because they're spawned at the beginning of the game all at the same time they're filling those four spawn points okay so let's go back let's remove this let's remove that and let's go back to this idea that when I press the GamePad I'm creating a local player so the issue here is if I press play every time I push that button it generates a new player and I think if I actually move off no it's maxing out at four so there's no way in this script that I've built for this to do a check and to stop replicating unless we use this variable I created of P2 spawn and have it do a check so after I create the local player I am going to set P2 spawn right and it's actually easier for me to just drag that in from over here and say set connect those pins and set this to true because now there is a player and then here I'm going to have a branch and that branch is going to ask is player to spawn true or false and if it's false create something and then set it to true and then I'm going to pull in the player to spawn and say get this condition and plug it in there okay let's make this a little bigger for a second take a quick peek at it so when Gamepad special right is pressed we check what the value of P2 spawn is if P2 spawn is false we create a new player and then we set the variable for true and now it's true anytime I press the special Gamepad again this Branch will say that it's true and nothing will happen okay here we are I'm going to press the button it's creating a second player there we go and I now have the ability to control both of them independently and we have our multiplayer local game up and running I think that's good for a first step on this tutorial I'll come right back with another tutorial about how to color code the players so that you can tell the difference between the two thanks for joining and please enjoy the rest of the series
Info
Channel: ProfMoto
Views: 1,176
Rating: undefined out of 5
Keywords:
Id: xhIVe588xdA
Channel Id: undefined
Length: 11min 12sec (672 seconds)
Published: Wed Oct 04 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.