Download

How to spawn new players in local coop and assign them a player controller

Hi,

so there are different threads regarding this specific topic already but none of them seem to have a solution that works for me (or no solution at all).
I think most of the problems are due to some missing basic knowledge about how the engine treats those specific things, so I hope you can help me out with that.

I’m trying to do the following: A game that is 1 v 1, as if it were a fighting game. No split screen, only one camera. Players have different characters depending on what has been selected in a previous screen, so what I need is basically this:

  • Create a player
  • Spawn the pawn selected by the player
  • Make it controllable.

My Gamemode has no default Pawn, as I need to control which spawn. CreatePlayer automatically makes it splitscreen, so it doesn’t work for me.
Thing I was trying to is just to spawn both PlayerController and the character with Spawn Actor, then possess it, and that works, but only for the first one.

Another big problem (or at least to me) is the way the characters are controlled. I need to have different setups:

  • Both players on keyboard (This works already
  • Player 1 on keyboard, Player 2 on gamepad
  • Viceversa
  • Both players on a gamepad (different gamepads)

Now, I only have two players right now, but that may expand to three or four. (So it would be something like 1 keyboard/3gamepads, 2 keyboard/2gamepads or 4 gamepads)

Currently I have this to spawn the character where I want it to and possess it
f849c821d8777804417cd48a0b04143a4b0ee02a.png

This is my Player Controller that I spawn (it’s from the thirdperson BP, just moved the things to a PlayerController BP). The character I created before is controllable when the Player Index is 1, and only when it’s 1. (Guess because 0 is the “empty” playercontroller that spawns automatically)

Both keyboard and gamepad control the first character.

If I use the same nodes I used to spawn the first character, another one spawns, but it’s not controllable. (The PlayerNum variable normally increases by 1 for each player, so it would be 2 for the second one. But neither does it work with 2 nor with 1)

So what would I need to do to make these things work? Thanks in advance