Local MP: Second player created; how to control it?

Hello. I’ve set the level blueprint to create a second player a few seconds after game starts (so the first player can move away from Player Start, just a rudimentary temporary solution).

The issue is that the second player doesn’t respond to user input, I have a X360 gamepad connected to the computer and, opposed to what I’ve read in an older thread, the gamepad doesn’t automatically take control over the second player; the X360 gamepad just controls the first player, and the same for keyboard and mouse.

I’ve checked through a “Print String” function that Player Index 1 and PlayerController 1 do exist; another prove is that, in the graph section showed below (level blueprint), the second player part of the split screen effectively is set to a camera (and that requires PlayerController 1 to exist as you can see).

So what can I do to make the gamepad take control over the second player?

I’ve finally done it with a C++ function in my GameMode subclass that calls this:

GEngine->GameViewport->CreatePlayer(1, Error, true);

Thanks to slayeruk for pointing it.

Both player are only controllable with two X360 gamepads in my case though. And at first the second player doesn’t spawn because the first one is blocking the Player Start; a timer call in the C++ code or a more complex spawning system can be used to solve that.

Is there a way to do this in blueprints?

If you mean calling the function, yes, I think at 4.2 or so Create Player was exposed to Bluperints.

Hm everytime i try to call this function is says its deprecated.
I should use:

CreateLocalPlayer(...) 
// but when i try to
GetWorld()->GetGameInstance()->... 
// i cannot get any further with this call: pointer to incomplete class type... same with this call: 
GetGameInstance()->

ok deprecated anyway… when i debug the game i get
Unhandled exception at 0x00007FF88BCD4287 (UE4Editor-Bily-7441.dll) in UE4Editor.exe: 0xC0000005: Access violation reading location 0x0000000000000000.

and this comes from

FString something{ "hello" };
GetWorld()->GetGameViewport()->CreatePlayer(1, something, true);

The first gamepad, the keyboard and the mouse seem to have the same internal controller id, which is 0. So you cannot easily control the first player with the mouse and the second using the first controller.

Creating a user via blueprints is done using “CreatePlayer” which can also simply be called in C++ with UGameplayStatics::CreatePlayer().

Marc

Yup, here’s an example:

98111-add_player_blueprint_node.png

I answered this question here.Hope it works for u .