Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

RPC not working on client when moving units

Hello everyone !

I'm trying to move a unit on a client and it's not working, while working perfectly fine on the server.

So my RTS Pawn has an array of selected actors, and will call the RPC for every single one of the unit (yeah, I know this is weird, I'm gonna change it but still). I use a BlueprintNativeEvent to link my C++ class with the BP child of that class (I use BP mostly for the viewport that C++ doesn't have T_T).

 // Called to move units
 void ACommander::RightMouseReleased() {
     for (AActor* actor : selectedActors) {
         if(actor->IsA(AFrench_TestInfantry::StaticClass())) {
             Cast<AFrench_TestInfantry>(actor)->MoveUnit(FVector(0, 0, 0));

And inside my BP, I do that :

alt text

This is only working if the server uses it. If the client try to call it, it won't even call the "ROS Moving Unit". So the RPC is not even called. Instead, only the "BEFORE ROS" is printed.

My infantries are Characters set to replicates & movement replicates. When a unit is moving, both clients & server can see it.

My guess is that it's coming from ownership, but I'm really not certain how to fix it. The Barrack is supposed to have the right owner (my commander) and give it to the infantry on creation.

Thanks ! :)

Product Version: UE 4.14
rpc.jpg (154.6 kB)
more ▼

asked Jan 30 '17 at 04:01 AM in C++ Programming

avatar image

146 17 18 29

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

I think you're right about the ownership. In order for a client to be able to call a RunOnServer event, that client's PlayerController must be the owner. In your case, the infantry units are controlled by the AIController that lives on the server. So that is the owner and because of this the client is not able to call the RPC on the infantry unit.

You could try to create something like a AIControllerManager. Each client should get one of these and it should be replicated so your clients can actually call RPCs and tell the server to call the Move To functions :)

Hope it helps, GL HF! ^^

more ▼

answered Jan 30 '17 at 05:11 PM

avatar image

48 3 6 7

avatar image Gnougnou Jan 31 '17 at 07:48 PM

Yup, that was coming from the ownership. I went for the "Go through Player Controller / Pawn" method. My barrack asks the Pawn to do the RPC and gives it parameters such as Location, Class, Rotation and Commander. The server spawn the unit accordinately. So all units in the games are owned by the server except for the player pawn and its controller, but a player can only interract with a unit whose commander variable is the same as the player pawn.

Thanks ! :)

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question