Get player index of who pressed key

Hello,

I am trying to get the player index of who pressed a key for a local multiplayer game.

This event exists on an object, and when there is an overlap, it checks to see it is a player character, and if so, it gets the player index (player 1 or 2) and enables input for the object.

This second event also exists on the object to allow the player to actually do the interacting. However, i run into the problem of not being able to get the player index of who pressed the key, so get player character is always index 0. I would need the player index to I can cast to that specific player, and in the case of this event, have the player pick up the object.

Any help would be much appreciated!

I never tried that as i didn’t do any local multiplayer, but i think if you place input even in player controler the events will be rised only when owner of that contoller, i think the same might be with possesed pawn, so try it out.

Either way i notice something strange in first graph how you handle controller, you doing it in very wierd way.

Get Controller->Cast to MainGamController-> Get Controller ID->Get Player Controller->…

You getting controller, you casting it and for some odd reason you getting it’s id to get controller all over again. MainGameController is already PlayerController as it inhrits from that class so you don’t need to get controller again or even cast it to PlayerController, all pin that that are parents of the class MainGameController: PlayerController->Controller->Actor->Object will accept it,
You only need to cast to highest class that you need, if you use PlayerController nodes only, you cast to PlayerController, if you use function inside your controller you cast it to your class, but from that cast you still able to use it as PlayerController so you don
't need to get or cast again, just once.

So you can use one that you got from Get Controller, the cast will fail if it’s not playercontroller anyway stoping the execution.

Hi Shadow,

First off thanks for the reply. I am new to UE4, so i have taken into account what you said about the second image and have “removed the middle men”.

As for my main question, if I place the inputaction in the character rather then in the object, then i would still need someway to pass the properties of the object through to the player character for him to be able to interact with it.

I guess I could create a variable within the character for intractable objects, but was hoping there was a way to get the information only when a button was pressed, not every time there is an overlap?

I’m guessing some kind of interface might be able to do the trick, but being new, I have not used them yet or know how i would go about implementing one, if it is in fact the right way to go?

I fixed the issue.

Just set up a variable in the overlapped actor called “OverlappingActor” that gets populated if a viable actor is overlapping.