How can i fix my replication process loosing reference to a variable?

Hello,
I have a system in place where if one player is on the enemy team and another player wats to be on that team they can request to “swap” This should send a message to the person on that team telling them which player wants to swap.

For whatever reason everything works fine for when the server is on the enemy team and a client wants to swap, but if its vice vera something weird happens.

About halfway through the back and forth of carrying over information, one of my events just loses its variable information. (a controller type). Its better if I explain with pictures.


Lets start here, this is in the widget

wanting to swap will ask the server to contact the gamemode and find who the person on the killer team is.

Not that all of these functions and events carry over the “person requesting” variable for future reference. In this function I’m checking who is the killer and then through the client’s controller, sending the request.

at this point the “requesting player” returns as empty

This is the widget that gets displayed (still shows up, just doesn’t have the proper name because variable is empty)

image

Is this really in the widget ?
Widgets are not replicated. You cannot RPC from client to server in a widget blueprint.
It may only work if client is a server (ie. host).

I don’t know how you manage your “Connected Players” variable, but chances are it doesn’t function in the same way as the GetPlayerController node does.
In completion branch, try to Get(index) from your ConnectedPlayers array instead.

image

Clients do not know about other player’s PlayerController, so this is not surprising.
Any PlayerController variable will become null when replicated to a client, except if it’s the client’s own playercontroller.
Instead, you should pass the PlayerState which is designed to be shared across all network.


No sorry that was meant for the picture above the text


Ah! thank you, I actually didn’t know that. So I would need to change the variable on “requesting player” to a player state. From that ill reference the controller. I will try this later and update the thread!

Your request must be sent from either Pawn or Controller to the servers variant, then passed to the other clients Pawn or Controller.

Actual swapping would happen in Game mode. Client B’s controller would call an event on its server variant which would call an event on the Game Mode.

Game mode on lives on the server. Clients do not get a copy.