Is this correct usage of RPCs? (high-level)

Hello everyone,

For some reason I seem to still be struggling to wrap my head around networking in Unreal. From what I gather, if an actor owned by a client, such as a PlayerController and a Pawn/Character, needed to replicate something, they would have to send it to the server first using a Server RPC, and then from the server use a NetMulticast RPC to replicate it to all the other clients. Otherwise, if it is an actor just placed on the level for instance, it is already owned by the server. Therefore, all you need is to call a NetMulticast RPC from the server only in order to get that to replicate.

Now let’s say I want the player to be able to attack. How would I handle the replication of that attack function? Let’s say for simplicity’s sake, all the attack function does is play an animation, and toggle a boolean variable. Right now, my solution is to have three functions; one for the server, one for the multicast, and the regular one. So the function runs, checks if it’s a client, if it is then it calls it on the server, which then runs it as multi. It works, but I have a feeling I’m doing something wrong. Maybe I’m just not used to it, but I can’t see myself having three functions every time I want something similar to happen. For example, if I right click for attack 2, that’s 3 extra functions. If I sheathe/unsheathe, that’s 3 extra functions. I also feel strange calling multicast so often, I feel like I’m abusing bandwidth by doing so. What am I doing wrong and what is a good way of handling the above problem?

Thanks for any help!

It’s true that whenever a client wants to do in action such as punch go stealth etc and the sever cannot know otherwise you have to send and rpc to the server telling it to update a variable that is replicated for example or a multicast, what I usually do is create one function that has some parameter like int WhatAction so 0 would be I’m punching, 1 want to use bandage etc and based on the action the server will act accordingly.

For the actor that is placed in the level and owned by the server if its marked as Replicate changes to movement, rotation etc will be replicated automatically, and variables that are marked replicated will be replicated automatically as well if they change on server.

It’s true that whenever a client wants to do in action such as punch go stealth etc and the sever cannot know otherwise you have to send and rpc to the server telling it to update a variable that is replicated for example or a multicast, what I usually do is create one function that has some parameter like int WhatAction so 0 would be I’m punching, 1 want to use bandage etc and based on the action the server will act accordingly.

For the actor that is placed in the level and owned by the server if its marked as Replicate changes to movement, rotation etc will be replicated automatically, and variables that are marked replicated will be replicated automatically as well if they change on server.
[/QUOTE]

Thanks for the reply. So essentially what I’m doing right now is fine? And yeah I like the idea of having a function that handles all the tasks, I’ll probably move some stuff around now.