Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Identifying player, local multiplayer

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;

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. alt text

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.



Product Version: Not Selected
ignoring.png (63.6 kB)
more ▼

asked Jul 08 '14 at 07:24 PM in C++ Programming

avatar image

73 4 8 10

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

Player State

In the player state class there is a unique ID value that will help you

/** Unique id number. */ UPROPERTY(replicated) int32 PlayerId;

Controller ID

The controller ID is not part of UPlayer, it is in ULocalPlayer

so you must obtain a ULocalPlayer in order to access this value

It can be accessed from the Player Controller Class!

 //           Get Local Player Controller ID
 int32 AVictoryGameSession::GetLocalPlayerControllerId(APlayerController* PC)
     ULocalPlayer * LP = Cast<ULocalPlayer>(PC->Player);
     if(!LP) return -1;
     return LP->ControllerId;

If you cannot find anyway to do this in BP (if you need to do it there), let me know and I can make a node for it



more ▼

answered Jul 08 '14 at 09:26 PM

avatar image

10.6k 446 345 1088

avatar image ghlkvf Jul 08 '14 at 10:58 PM

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).

alt text

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.

ramaresponse.png (145.1 kB)
avatar image Rama Jul 09 '14 at 09:35 PM

"Again, thank you. Your tutorials have been extremely helpful in breaking into the engine."



Yea I think I will need to make a BP node for this....

avatar image Rama Jul 09 '14 at 10:26 PM

Two BP Nodes For You

I have added two BP nodes to my Victory BP Nodes Plugin!

Get Controller ID ~ takes in player controller and gives the ULocalPlayer's ControllerID

Get Player State PlayerID ~ returns the replicated unique PlayerID for the supplied Player Controller!

 bool PlayerController_GetControllerID(APlayerController* ThePC, int32& ControllerID);
 bool PlayerState_GetPlayerID(APlayerController* ThePC, int32& PlayerID);


You can download from original post of this thread!


avatar image ghlkvf Jul 09 '14 at 11:03 PM

Thank you Rama, this is perfect! (I had no idea about your plugin either, it looks great)

I don't know how to mark this as answered so if one of the mods want to do that it would be much appreciated.

avatar image Rama Jul 10 '14 at 08:31 PM

you're welcome!

To mark this answered you click the check box next to my original answer :)


avatar image MStory Apr 08 '18 at 03:16 AM

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.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question