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 :

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 ! :slight_smile:

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 :slight_smile:

Hope it helps, GL HF! ^^

More info on A new, community-hosted Unreal Engine Wiki - Announcements - Unreal Engine Forums (Rules for calling functions)

and: Actors and their Owning Connections | Unreal Engine Documentation

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 ! :slight_smile: