How References are managed in Server RPCs

Thank you for this great course,
I have a question about how references to actors are passed from a client to the server.
I am working on a multiplayer game in which the clients can ask the server via an RPC to delete some actors from the game’s scene. The reference to the actors that should get destroyed is returned via a raycast hit. Now my question is if the references are nothing but the memory location an actor is in it. How can the server get that reference via an RPC and correctly delete that actor. For sure the memory location of the actor on the client’s machine differ from the server machine.
The ServerRPC’s parameter is of type (AMyCustomActor* ActorToBeDestroyed)

I’m not even sure how this would work. The normal way would be for the server to perform the deletes and this automatically replicates to to the client.

I think you might be best to ask this on the discord as someone may have the answer there. Sorry I can’t be of more help.

No Problem at all. Thank you for always being helpful. And regarding the normal way of deleting that is the case but it does not work for an RTS games. Since in these kind of games the clients should be able to give order to their units or delete some of their units for some reasons

That is true, but what they should do is inform the server this needs to be done and the server should perform the delete. This mechanism is to prevent cheating. The server should be the only location where these actions take place otherwise a client could cheat.

On the server, upon receiving this rpc, the server must obtain a pointer to the actor and use it to remove the corresponding object from the game scene.
Make sure the client has the right to request the removal of a specific actor. Don’t trust info sent by the client and always check with the server that the client has access to the requested actor.

You can use Validation to handle this and if validation fails, the player sending invalid data is kicked. This protects the game

Thank you for your responses. What I have done so far is to have the client check whether it has permission to request the deletion of an object from the scene, and then the request is sent to the server via an RPC. However, I’m considering adding an extra step with validation methods to ensure there is no cheating.

My main question and area of curiosity is how pointers are handled in RPCs. There must be some Unreal built-in system that translates a pointer to an actor into something that is consistent across all instances of the game.

Well, at a guess anyway, and this would need research, pointers are referring to objects. It is these objects that are replicated and deleted. The pointer itself (ie address) cannot itself be common but the data it refers to can be. I imagine there is some unique ID in the object that is used to handle this sort of operation but again I can’t be sure.

I am also making an RTS game and I’m looking for an answer to this. I need to send an RPC to request that the server move a specific actor, but I cannot figure out how to tell the server what actor that I want to move. What does the client version of the actor and the server version of the actor have in common, so that I may reference it on the server and have the server perform the action on that actor?

This is beyond the scope of the course. Saying that, if the RPC call originated in the actor itself, this would be called on the same actor server-side. This may what you’re looking for but I can’t really help beyond this.

Privacy & Terms