How to replicate an event to a specific client only?

Client that you only want to replicate within an event can pass PlayerState.PlayerID into it via Server call. Then within the Server event, check if the passed PlayerID matches the current PlayerController’s PlayerID. If so, then perform you want to replicate, otherwise, do nothing.

Below is my example:

  1. Create a GetState (returns PlayerState) function inside your PlayerController.

266936-e1-getstate-function.png

  1. Create GetPlayerID function inside your PlayerController.

  1. Create IsCurrentPlayer function inside you PlayerController.

  1. On your Server event, compare the passed object’s PlayerID with the current PlayerID. If they match, then it means that the current player evaluating the event is the same as the one who called it via Server RPC call.
    Also, if you want to replicate it to other clients except the caller of the event, just use the False connector instead of the True one.

Now that you know how to do it the hard way, here’s the magic way of doing it:

  1. Pass the Client’s PlayerController that called the event via ServerRPC. Inside the event, drag the connector from the passed PlayerController input and then use the IsLocalController or IsLocalPlayerController node. True means that the current player evaluating the event is the same as the one who called it via Server RPC call.

2 Likes