UE 5.3.2 Multiplayer replication problems (interaction)

Hey everyone
I have a very basic question regarding replication as I’ve just started getting into making a multiplayer game but I’m already stuck, followed through a few tutorials but for some reason I can’t get basic stuff to replicate, in this example, I just wanted to test a basic line trace interaction to destroy an object using an interface:
Code in character


Interact function

Code for the interactable actor

The interaction works fine for the server side and replicates (the actor gets destroyed) but doesn’t for the client (as in nothing happens on either sides when the client tries to interact)
What am I doing wrong or not understanding?

your trace is using the camera location but the server wont have the clients camera.

what you could do is run the trace on the client and then validate on the server however you want

If you want to use the client’s camera on the server, then you should probably use it through the player camera manager from the player’s controller, which is replicated - alternatively you can use GetPlayerViewPoint from the player controller

So one approach would be to call the server event, the server does the trace using the client’s view point (or GetCameraLocation from player camera manager), and then the server will probably multicast the interact logic only, and not the trace
You could still be running a local trace to for example trigger ui elements, but not to actually interact, unless you want to do some complex predicted interaction system, which I don’t think you want to do

A couple of things to remember:

  • Player controllers (and their player camera managers) only exist on the owning client and the server, but not on other clients. So Client B doesn’t know about Client A’s player controller (or camera)
  • Destroying actors should probably only be done on the server. No client can destroy actors, unless the actor was specifically spawned by that client (which would make the actor local to that client only)
  • Multicasts can get culled depending on distance of client from the object. So if you want to somehow modify the object you will have to do it through replicated properties, which will get replicated when a client is in range, or even joins later. A multicast would not be received by late joiners or clients that were too far away and then get in range.
  • Destroying an actor on the server will destroy it on all clients, regardless of distance

Looking into the gameplay ability system could be beneficial, since abilities support networking out of the box, and prediction to some extent. You can use the system with BP only, unless you want to create attributes, which unfortunately can only be done in C++ atm

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.