Client to Server Replication on World BP Actors

I have spent the last few days banging my head against the wall going through all the documentation with relation to Network Replication, Multicasting and all topics in between. I have a very simple project with various objects that I would like players to click on them and change their material or perform other simple functions. It works fine if the server performs the action, all clients can see the changes. I just can’t for the life of me figure out how to have the clients tell the server. I thought all that is required is a Custom Event with Replication set to Run On Server. Alas the command dies for the clients at this ROS Event.

From documentation and the AnswerHub it seems like an ownership issue, everything needs to be performed under the PlayerController or Pawn, they then perform and ROS Event and the server carries out the function, multicasting to the clients. This seems like a messy way to communicate with a bloated PlayerController. I was hoping to easily duplicate my Actor BP for other objects, keep everything tidy etc. Then this asset can easily be used in other projects.

Here is what I have running on a cube in my level which was converted into an Actor BP:

Any help will be much appreciated.

In your case you only need multicast. Run on Server is only ran on the server instance of the actor, whereas multicast is ran on all instances.

This video helped me a lot:

Thanks for replying.
I have tried this but using only a Multicast event only updates the individual client who performed the action, the server doesn’t see the update and neither do other clients.

Hi, thanks for these.

I have already gone through the whole UE4 videos series. I believe it all makes sense to me about server and client communication and replication. My issue seems to be coming from the fact I am not triggering any of this from within a PlayerController.

I was hoping to have this contained within a standalone asset which can be moved to different projects and perform the same action.

For example I have a BP Actor which is a sofa, I create a function which changes the colour of the sofa when a player hits it, I would like the whole blueprint structure to be contained within this asset so it can be easily reused, not within the PlayerController where every new project the code will have to be recreated, or copied from the previous PlayerController. In the end I would like to build a bunch of furniture assets which can be used in various projects, hopefully by simply merging them in.

I am obviously getting confused somewhere but can’t for the life of me figure out where. Does the code have to be contained in the PlayerController? Is there a way of casting this from a object placed in the world? Whoever ‘hits or clicks’ the object tells servers to Multicast the material change.

Thanks again,

My best guess is in how you’re triggering the event. Try triggering the material change through an overlap event. Also, is your actor set to “Replicates” in class defaults?

So, I have it working. The issue is what I thought it was. Any replication command has to be called within a PlayerController or a PlayerPawn. It is not as clean as I had hoped but a halfway house solution is to use a Blueprint Component. This BP_Component contains all relevant functions and events. It must perform a ‘Cast_To_PlayerPawn’ or controller and pull a reference to an actor variable of what the player has clicked/hit. Then the Material ID variable is set. The ROS and Multicast Events need to push through the Mat ID and the ‘Hit’ actor variable.

So the lesson I have taken away from this. All two way replication events should be contained within a Pawn or Controller. I wish the documentation made more of a statement about this. Maybe I just missed that part.

Hi, the only client that can run RPC Commands (like execute on server) is the client that owns the actor. So one thing you could do is dynamically change the owner of your furniture actor. In your controlled pawn/controller you would call an RPC so that the server would set the new owner.

Then in your furniture actor the server sets the new owner. This enables the new owner client to call RPC events (like run on server) on the furniture actor.