Hi there! I’m currently working on making a 2 player co-op 2D puzzle platformer and was wondering how to go about spawning the players in? Right now I have both characters as children of a parent character class BP that holds basic control/movement info and the characters have their own unique code for their abilities. I haven’t been able to find a tutorial that helps as they all deal with having the same character spawn in multiple times. I have an idea for how I could go about it but I’m not sure how to execute it or if it is even efficient.
My idea right now is, make the characters their own blueprints as pawns and have player controllers posses them after play is pressed. I would probably have the characters physically in the level and do an on begin play in the level blueprint to have the keyboard posses character A and the controller posses character B (not sure how to write this out in blueprints). I’m also not sure if I can do this with the children blueprints but if I can that would be preferred if its not to difficult. I’m also not 100% sure how player controllers work, I’m having the parent call the default one right now but I tried making my own and the characters wouldn’t move so I went back to the default.
You dont need the characters physically in the level. Your GameMode is spawning the pawns and the player controllers. Override the functions there to spawn different pawns for each controller at the correct starting positions.
This is the default setup of local player controllers as long as you have Project Settings → Maps & Modes → Local Multiplayer → Skip Assigning Gamepad to Player 1. (There you can also disable split screen)
Then it’s just a matter of setting your Enhanced Input to work with both keyboard and a controller. The hardware input will be correctly assigned.
There should be no problem making your own Player Controller. I’m not sure what exactly is that you are asking about child blueprints. I guess the answer should be “Yes” since everything is pretty much “child blueprints”…
Set this up in the GameMode and have my input actions assigned for both controller and keyboard but I couldn’t move the second character. Both the controller and keyboard only affected the first character.
Set Default Pawn Class For Controller can setup the pawns for the players based on some predefined condition or what the players have chosen.
Find Player Start can give you different start actors for each player.
There are a bunch of useful functions there that have a default behavior and are already responsible for starting your game, spawning controllers and pawns. Override the ones you need to work differently.
Didn’t know where to go to actually override the functions, thanks for showing me.
I have a few more questions as well. Sorry if they are really basic or seem overly general, I’m pretty much clueless when it comes to messing with GameModes as I’ve never done it beyond what you can change in the project settings.
Do I need to assign individual PlayerControllers to each character or can I use just one?
Do I need my characters to be Pawn Class Blueprints rather than Character class Blueprints? It seems like the Gamemode deals with assigning controllers to pawns.
Which function would I override to actually spawn in the 2nd character and have it be controlled? I was able to spawn in the 2nd character with the BeginPlay event but despite having keyboard and controller mapping set up neither would control the 2nd character, only the first. You mentioned Set Default Pawn Class for Controller but the closest function to that on the list is Get Default Pawn Class Controller, I’m not sure what the difference is.
This one is separate from GameMode but do I need to have separate InputMappingContexts for my characters? I’m not sure if them using the same one is whats causing the controller and keyboard to only work with the first character.
The player controller is the abstract representation of the player. They are made with networking in mind so each controller holds a network channel, hardware input and a viewport (among other things). You can control 2 characters from the same controller and it’s the only way if you watn two characters to both be moved with the same hardware input (keyboard for example)
No. The character class derives from pawn which means that the character can do everything a pawn can. (character is pawn)
On Event Begin Play call Create Local Player in your Game Mode.
Each controller is associated with a hardware input. For some reason the default is that the first player gets KB+mouse AND the first controller. You should go to your Project Settings → Project → Maps & Modes → Local Multiplayer and enable “Skip Assigning Gamepad to Player 1”. (disable Use Splitscreen while you’re at it.
Setting this up in my Gamemode does spawn in a second character but it is a copy of the character I already have. I am trying to spawn in a different one. I tried using the SpawnActor node to spawn it but when using either or even both of these nodes I could not control the second character.
Skipping assigning the gamepad to player one didn’t do anything for me. Both the controller and keyboard were tied to the first player. I even went so far as to buy a second controller since someone I know said they couldn’t get multiplayer to work without using two controllers and despite both being registered by UE I still could only control the first character and the second controller wouldn’t do anything. I tested both controllers outside of UE and they worked perfectly.
This is the BP set up I have for the parent BP of my two characters. I’m not sure if this could be something that is causing the issue but I figured I’d share it.
This worked for spawning in both characters but I can still only control the character that is set in option 1 of the select node, I’m still unable to control the second character.
Is there a seperate “player controller” setup? And is it set to the second child classes default or override? Or on spawn are you spawning this controller and possessing this actor? Few things to try hope will help
As of right now I have both characters using the same character controller BP that the parent calls, which is the the one I have set as default in the game mode. I was under the impression that they could share one
Tried it using Unreal’s default input mappings and it still doesn’t work. From what I’ve done it seems like the second character isn’t being possessed by a controller since when I have the actor spawned in and the inputs set to just print a string nothing happens
Key events, if you right click under “input” maybe try adding some random key event with a print string to the characters bp that’s not working to see if that will do anything