Local multiplayer with shared controls

Hello guys,

A bit of context: I’m creating a fairly simple, turn-based, two-player game that should be played locally taking turns/sharing a mouse. There’s a small UI (UMG) with three buttons that allow players to do actions. Right now, as I play the game, a single PlayerController is spawned, a single Pawn is spawned, etc.

Questions:

1) How should I spawn a second player?

I read that I could call CreatePlayer from the level blueprint for instance, but I’m not sure that’s where this kind of management should be done. I was expecting to have such a function available in AGameMode. Or, even better, a player count that I could simply increase to two.

2) Controls are shared (mouse is shared, actually), so, should I have one or two PlayerController instances?

I was thinking of having a single PlayerController and possessing the correct player pawn between turns.

3) How do I spawn two UI’s, one for each player?

The idea was to have one set of buttons on each side of the screen. The issue here is that it seems that the UI has to have an owning player, and right now I have no idea how to properly associate it with the player (I’m doing it on the Level Blueprint, as below).

Hi HeavyStorm

1) How should I spawn a second player?

Spawn the second player (pawn / character) just as you would any other actor using the “Spawn actor from class” function. Realistically it should be handled by the GameMode, but if its a small game, you can use the Player Controller.

2) Controls are shared (mouse is shared, actually), so, should I have one or two PlayerController instances?

I was thinking of having a single
PlayerController and possessing the
correct player pawn between turns.

That is exactly as I would handle it. When switching turns, unpossess the pawn / character for player 1 and then possess the pawn / character for player 2.

3) How do I spawn two UI’s, one for each player?

I wouldn’t use the level blueprint, stick the player controller.
The “owning player” refers to a player controller, so having multiple characters / pawns is not an issue.

Having separate UI widgets for each player would be tricky in the sense of managing both UI’s as removing / readding the UI will reset variables to their default states so you will have to reconstruct them each time. I would use a single UI and just hide / unhide the UI elements for each player.

If you have complex UI and require each player to have their own instance, store the data the UI needs inside the pawn / character and get the UI to read the data using “GetControlledPawn”.

Hope this helps

Alex