Get the client player controller from a server player controller?
I'm not actually sure how to word this one, But what I'm trying to do is grab the clients version of a player controller from a specific server player controller.
For an example lets just say we have Player 1 and Player 2
Player 1 has these two controllers: ServerPlayerController ClientPlayerController
Player 2 has these two controllers: ServerPlayerController2 ClientPlayerController2
The clients can of course only see the client controllers, and the server the server controllers.
Now the controllers for each respective player have to be connected in someway, I'm trying to find out how to get for example, ClientPlayerController2 from ServerPlayerController2
It's a bit confusing I know, but the main reason I need it, is because the method for attaching armor in my game to players, does not seem to be replicating to the client as it should.
I tried two difference methods but both had the same result.
First: I tried a "Run on Server" Replication event which ran into a "Multicast" Replication event which equipped the armor, and it worked to a degree. The server could see the armor attached on the client(s) and itself. But the client could only see armor attached to itself, the server and other clients armor would simply fall off.
Second: I tried having a "RepNotify" variable which was a reference to the armor actor I equipped. And of course when I changed the value of that variable it ran the equip armor code. But the thing was I got the exact same result, which was that Client could see only themselves with armor on, whilst the server could see everybodies armor.
This is due to the code trying to attach the armor to ServerPlayerController instead of the clients controller. I assumed multicast would work as it's running on all the clients controllers as well, but it still seemed to only grab the servers controller.
Now I'm thinking that if there's a way to just grab the ClientsPlayerController from a servers one, I could just attach it to that, so when I do a multicast, the code will only ever attach to the ClientsPlayerControllers. That way it's guaranteed the clients can see the armor on each other.
If this doesn't make any sense, Lemme know and I will try and clear it up. Maybe it's not even possible, but this is the only way I can think of doing it.
Any and all help is appreciated
asked Jan 31 '16 at 06:52 PM in Blueprint Scripting
Alright I got it! Turns out the functions I had worked perfectly, The problem was I was doing all of this in my player controller.
I took the same code (I modified the parent of the attach only) and shoved it into my actual player character blueprint. Then I redirected the interface message to go to the character instead, and now it works perfectly.
answered Feb 01 '16 at 02:54 PM
It is something quite weird. It is easier than you think, but complex to understand.
I suppose you are using BluePrint, not C++ It is same code which is running on server and client, so to differentiate where you are, you can use the has authority. So on your client, playercontroller is your player. You use has authority remote pin to work on your controller on client side. For know, if you want to apply action on this player controller, on server side, you will create a custom event, run on server. The best is that the event is defined on playercontroller blueprint. in this way, player controller client and server are directly connected, without give any reference or id. Or you can put a "in parameter" a player controller reference. It will automatically converted to one side or the other.
If action is on server side, for example, you detect a collision on your pawn, from which you can retrieve the player controller which possessed it. But you have to test before has authority with authority pin. After that, you can create a custom event, running on owner side (client), or broadcast to all user. Best is that this event is on plyercontroller blueprint...
I ve tried to summarize some information on my blog, if it can help you: http://thyshimrod.blogspot.fr/
answered Jan 31 '16 at 07:05 PM
Follow this question
Once you sign in you will be able to subscribe for any updates here