I have been struggling to make a blueprint graph which could let me access the player’s number in a multiplayer LAN RTS game. What I am basically aiming for is a functionality making the actors distinguish which actions are done by which players. For example, a red actor should only listen to a Move Command given by Player 2 and Attack Command given by Player 3, whereas a green actor should only listen to Move Commands from Player 3 and Attack Commands from Player 1. What is the easiest way for the actors’ BPs to properly execute such idea?
As I haven’t managed to find a straightforward node of doing that I thought of some workarounds which do not work unfortunately.
One supposed solution I tried was to get the PlayerID with PlayerState on EventPostLogin in the GameMode BP and as each player that joins the server gets an ID=ID of previous player +1, I tweaked those values to get the players’ numbers. It somehow did not work and maybe that is a good thing since the ID method is not very reliable.
Hey , thanks for you answer, but can you explain with more details, please ? Do you mean, that every player that log in have to take different controller, and how they should be assigned?
No, they will have same PlayerController class, but spawned objects of that class are unique and you can use to identify invidual players. Objects (blue links and pins) are really memory pointers, they contain memory address that points to data of object, if you compare the two (with “==” node) you check if they point to same address, if they does it means you dealing with same object. So you simply check if PlayerController that issue order is the same PlayerController (that you hold in some varable) that have permission in specific unit, simple as that. In you PlayerController if you want you can generate unique id too.
You might seem player id used in engine function, but if you look on code of those functions you will see, it’s just PlayerController pick from found in iterator (which assuming it is used for id, it means it always stacks PlayerController on top of another), 1st, 2nd or 6th found, it’s not something assigned direcly
Hi, again. Just to clarify I’m 3D artist and i work with BP only :).
Btw i can’t open that page at github(error 404).
I will show you what i made for simple test in Player Controller class BP and maybe in this way you can help me easier. When a button is pushed in Widget BP i call an event (Next Player) at Player Controller BP, you can see the rest in the screenshot.
“Set variable” works only separately for each player, although it’s replicated!
Assign IDs in GameMode on Post Login even, it will have PlayerController argument of player that, just cast it to you PlayerController class and set id varable or call some function that will assign it.
And again you don’t need IDs just compare PlayerController variables, in unit make a variable which contain PlayerController that owns unit and when you issue order with some function, make argument there of PlayerController that issues order and compere PlayerController from argument and PlayerController of owner variable, if it’s the same then you do the order, simple as that. UE4 don’t have IDs because this is how engine expect you to check what player does what.
And don’t excuse yourself that you are 3D artist i think you should able to understand what i said.
Thank you for the help , much appreciated. My biggest mistake was that i understood one basic logic of the engine in wrong way. I made it, and it’s working :).
what you should do, I believe, is on gamemode → event post login, create a global variable that increases every time a player logs in… then insert this id to the playercontroller (Event post login has a controller variable, drag it and set player controller id)… then set this ‘global variable’ to the player… so every time you use “get player controller”, instead of 0 you will use the global variable stored (as identifier) in the player.