How can I send data over network to only one client?
Here is the deal. We have an online game in UE4. Replicating stuff from client to server and from server to clients isn't that much of a problem BUT here is our use case: Each player has 1 character to control. Server calculates "visibility" of each character towards another player. So for example if S (Server player) is behind C1 (client one player) and C2 is seeing both of them, we want to send data to C1 only so that he hides S character on that machine only.
How do you send/replicate stuff to one client only?
asked Mar 15 '19 at 10:22 AM in C++ Programming
As Lafolie mentioned, I think that the best way to achieve what you want is by using RPC calls. Here is a simple setup to call a function only on a given client :
Inside your player controller class' header (make sure not to forget the _Implementation in the .cpp part) :
Then server-side, you call the function on a given controller :
This RPC call will only be wired to the client owning the player controller.
Hope it helps!
Hi Pablo1517. the concept you are dealing with is known as Actor Relevancy. You can find details on how this works in the docs here. There is also another means of controlling relevancy but it is more catered towards games with a large replicated actor count (such as a multiplayer game with a large number of players like Fortnite or PUBG).
By default the engine employs a distance-based relevancy policy, which sounds similar to the solution you want to employ. It's not clear from your description what exactly you're trying to achieve; if using less bandwidth is your concern then you should probably have more faith in the engine, or you can adjust the update frequency - the replication is quite efficient for what it does (the default distance is quite large yet still performs well!). If the hiding is a mechanic in your game (such as fog of war) then you might consider using RPCs to handle this instead of net relevance.
Follow this question
Once you sign in you will be able to subscribe for any updates here