This is really an xpost between blueprint and c++.
Our game has local split screen multiplayer (2,3 or 4). We have up to 4 characters (all the same character right now) in our game that upon colliding with collisionbox calls a function in our a custom game mode class, which inherits game mode.
void EndGameEvent(APlayerController *endPlayer);
What we would like to be able to do is to identify which controller number or viewport or something 1-4 or 0-3 so that we can say player 1 wins. We are looking for a way to access the controller ID but haven’t been able to find one.
Our original attempt to circumvent not being able to find the controller ID was to save a reference of all of the PlayerControllers in an array then pass in the PlayerController associated with the triggering of the event then compare.
int i = 0;
bool isFound = false;
for (; i < 3; i++)
{
if (pcArr[i] == endPlayer){
isFound = true;
break;
}
}
What we found doing this was that the playerController passed by the function either always finds a match (the same match regardless of the controller that caused function to be called) or it doesn’t find one. IE. It always says player 1 wins or it doesn’t find the player controller.
Ignoring the other strings on this blueprint (other failed attempts at fixing the problem), this is essentially how we are attempting to get the playerController that caused the event.
Does anyone know of a better way to identify which player caused the event? It really seems like controllerID is something that should be accessible to me but I’ve yet to find a way.
If you need any other information that may help you answer the question, please ask in a comment below.
Hi Rama, thank you for your help. For whatever reason my home computer doesn’t like building the project in visual studio so I won’t be able to attempt anything in code until I go back up to the Uni tomorrow. I did however attempt some stuff in the blueprints (which my partner is far better at than me).
I’m not sure where to get the Player Index for the Get Player Controller node so I’ve just connected it to the Other Body Index part of OnComponentBeginOverlap. I then did a Get Player State from the return value of Get Player Controller. The Player State doesn’t have access to the PlayerId in the editor as far as I can tell (version 4.1). If this is the correct approach (in terms of where the index came from) I can build the node tomorrow for returning the PlayerId.
Also, I tried casts to PlayerState and casts to PlayerController based on the Other Actor that OnComponenyBeginOverlap provides but both casts fail printing “Hello” and “hello again”
Again, thank you. Your tutorials have been extremely helpful in breaking into the engine.
Thanks Rama, your plugins have helped me tackle a very difficult problem i was having with my project. Literally tearing my hair out trying to find a fix and your plugins did the trick. Thanks again for your help.