No announcement yet.

LineTrace pitch axis replication

  • Filter
  • Time
  • Show
Clear All
new posts

    LineTrace pitch axis replication

    Hey guys,

    I have a problem with LineTrace replication.

    If Player 1 aims at a point higher or lower then him, everything seems to be okay.

    Player 2 howerver can see, that player 1 aims straight forward. It doesnt matter if someone is the server or a client. The pitch axis only gets updated on the own client and never replicates.

    How do I fix this?

    Click image for larger version

Name:	Line_trace_problem.jpg
Views:	2
Size:	147.2 KB
ID:	1528432
    Attached Files

    Are you running a dedicated server or is "Client 1" running as a listen server? Posting your event graph would be helpful but I'm assuming you're running a line trace on event tick in the character blueprint.

    In order to have all clients see this line trace, all clients must execute this line trace.. and in order for that to happen, the server must tell all clients to execute it. Keep in mind that replication only occurs from server to client. If a client wants to communicate with the server, they can run a remote procedure call (RPC) to send information to the server.

    This setup should work regardless of if you're running a listen server or dedicated server:

    1. Event tick. Clients and Servers run the same exact code (unless you specify otherwise, see step 2). There is a copy of the player's pawn on both your client and the server. Event tick is being executed for each pawn on both the client and server. If you're running a dedicated server, this means this fires every tick for 4 entities. If Client 1 is a listen server, then it fires 3 times. You should always be careful when using Event Tick in a multiplayer game for client/server interactions because it can flood the server with network traffic.
    2. Switch: Has Authority. Since both Client and Server run the same code, we need to use this authority switch to ensure the following code only runs when we have "Authority" .. meaning, when the server is executing this code. If we are "remote" (client), we can stop execution here.
    3. Now that we ensure we are executing on the SERVER, we can replicate to all clients. So create a new custom event, let's say it's called "DrawLineTrace". Edit the properties and select "Multicast" - this will ensure this event executes on all clients (and the server).
    4. From the "Authority" switch, call the DrawLineTrace event.
    5. With the DrawLineTrace event, you should be able to execute the line trace as you have before.

    Edit: The above is not optimized for performance and may cause slowdowns with enough players or enough other stuff going on. I'd say there's 2 major points of slowness.
    1. Running a trace on event tick. If it truly does need to be done frequently, I would at least check the player's rotation to see if it had changed first and only run the trace if it has changed. If it hasn't changed, you could have the result of the trace stored (store the start and impact point) and I think you could draw a debug line between two points instead.
    2. Running the trace on every client. This is a calculation that may be unnecessary to run everywhere. They should all do the same thing.. so why not just do it once on the server then tell the clients where the impact point is? You could run the line trace after the "Authority" switch then pass two vectors into the "DrawLineTrace" event and have the clients draw debug lines based on the 2 points instead. But it all depends on what information you want to get from the trace as well.
    Last edited by Chumble; 09-18-2018, 01:59 PM.


      First of all, thanks alot for your help!

      it replicates now, but I cant use it to interact with anything. For some reason, there is still the old line trace that doesnt replicate in the pitch axis. But its the only line trace, that works properly when it comes to interaction with other things.

      Any idea how to fix this?
      Attached Files