2D Side Scroller Client Aim at Cursor Replication

Trying to replicate client to host aiming at cursor. Host replicates fine, but other players just aim at 0,0,0 on every screen except their own. Setup is in player controller, using “convert mouse location to world space” for mouse data. The “component replicates” box is ticked, and replication that worked previously for other inputs is attached below.

I see a number of problems

  • Your event Tick is running on both client and server, so you’re Multicasting twice per frame which is highly inefficient.

  • Multicasting every frame is highly inefficient. Use variable replication for server->client replication for this kind of thing.

  • Your logic is essentially doing the following : Tick(client) → AimAtCursor(client) → AimServer(server) → AimMulticast(client). You are not passing any parameters to these replicated calls. You could execute whatever you are doing in “AimMulticast” directly in Tick, and obtain the same results.

  • Client machines only know about their own PlayerController. Other controllers do not exist on clients. So using Multicast on a controller doesn’t make sense, as a controller can only replicate (functions or variables) to its owning client.

  • You are not showing the part of the code that actually rotates the pawn. I am curious about this as it is usually done via Pawn->RemoteViewPitch but that stuff has never been properly exposed to blueprints.

So with all this, let’s see how we can make things work.

The server doesn’t know about client’s cursor, so things like “ConvertMouseLocationToWorldSpace” should only be done on client. Once you’ve computed things, send result to server.

Now next part I am not sure because I don’t see what you are doing. Considering you are saying it works for the host, I suspect you are setting variables that are already replicating by default and you don’t even need to multicast.

If that’s the case, then you have nothing more to do :

1 Like

Thank you for the in depth reply! I’ll need a while to digest and test everything here

Got it working thank you so much, been stuck on this a while.