Is there a way to replicate values just to some clients?


Is there a way to replicate values just to some clients and therefore preventing clients from knowing things they shouldn’t know about? I want this behavior to prevent clients from cheating. I guess 100% cheat free is a little much to ask but at least not allowing game breaking cheats like (in my case) eg. map hacking in a RTS.

I know units that are “too” far away can be configured to not be replicated but in my case a unit can stand next to another unit and not being visible or being visible across the whole map.

You can use conditions to filter the replication of that property to certain clients. The most appropriate check that exists is probably filtering to the owner.

DOREPLIFETIME_CONDITION( AActor, Property, COND_OwnerOnly ); // Send only to the owner of this actor
DOREPLIFETIME_CONDITION( AActor, Property, COND_SkipOwner ); // Send to everyone but the owner


You can check out the other conditions as well, though the rest may not be appropriate for what you want.

Am not sure I understand how I can achieve the behavior described above. Lets say e.g. if three players currently should have vision of an unit (i.e. Actor) how can this be achieved?

Also how do you set a client to the owner of an Actor, is that setting the PlayerController to the owner?

What you could do is replicate the particular variable using a function… i.e.

// you might not want it to be 'Transient', that is just what my example has
UPROPERTY(Transient, ReplicatedUsing = YourFunctionToCallOnReplication)
variableType yourVariable;

then, it will be replicated to all the clients, but inside the YourFunctionToCallOnReplication() you could do the checks to do the things you want.

void YourFunctionToCallOnReplication(){    
    if(checkThis && checkThat || whateverCheck){
        // do the desired behavior [unitVisible = true]
        // do something else or nothing [unitVisible = false]

This might not fit your implementation… but maybe you can use it to get the desired result.

Yes, the owner would be the machine that owned the player controller of the actor in question.

In my example, it will allow you to filter which machines see the property change of a single actor, and in this case, it would be either the owner or not.

One thing you could do with this, is use a struct or something, and use the condition logic to only send that struct to the owner. Then, you can populate that struct with only information that owner should know about. The server can then take advantage of this, and use that to send and filter information to individual clients (it can populate each owners private struct differently, based on filters).

If you don’t mind the client getting the property, but then throwing it away (OnReps are triggered on the receiving side), AnXgotta has a perfectly reasonable solution, and we do this internally. This is slightly dangerous if you’re worried about cheating, since the client has this info, but is simply ignoring it. They would need a modified client to exploit this though.

If you absolutely don’t want the client having this information, you need to do this server side.

In your specific example though, of 3 players having vision of a unit. You could modify the relevancy checks, and factor in teams, or whatever filters you want.

So if a unit is visible to 3 of 5 connected clients, you could force false in the relevancy check for clients that shouldn’t see that actor.

AActor::IsNetRelevantFor is where you would want to look. This will work if you want to physically control which actors get sent to whatever connections.

This is a much more elegant solution. Explained well too.

This doesn’t work out of the box I think but could maybe be used to implement a good enough solution. One problem would be that the checks are performed on the client. Also e.g. the actor’s position is replicated even if this client shouldn’t know about this actor at this moment, and I can’t turn that off since other clients may need that update.

I will investigate the possibilities with this more if I can’t find a solution on the server. Thanks!

Johns solution will work better for security reasons. As you and he said, the client will never get the information.

This sounds like a nice solution. Thanks a lot!


Do you have any references to IsNetRelevantFor() in use?

I am running into a situation like the end of your answer, where I want to control which actors go to what connections, but I can’t seem to make sense of how to actually use the function. I’ve overridden the function on my Pawn, but I can’t seem to find any code examples where this function is actually called and used.

Any why is there a location in this function prototype? What does it actually do for the function?