Announcement

Collapse
No announcement yet.

LineTrace pitch axis replication

Collapse
X
  • 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

    #2
    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.

    Comment


      #3
      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

      Comment


        #4
        I need some clarification on what is happening. This problem only exists with client 2, correct?

        So what it looks like from the blueprints you have

        1) Client 2 calculates its line trace in the world
        2) Client 2, on event tick, sends the start and end points from the line trace to the server
        3) The server then tells all clients to draw the line trace from the points sent from Client 2. At least I'm assuming that's what is happening in that "Interaction_Tracer" collapsed graph.

        I like the use of the "Switch Has Authority" when running the SERVER_Interaction_Tracer, by the way. It should be redundant since that event should only ever execute on the server but I like that extra safety net, plus it adds to the clarity of where this code is being executed at a glance.



        Ok, so Client 2's line trace is being replicated across all clients, right? Looks like everyone can see Client 2 is aiming up. But the problem is when Client 2 tries to interact with something, it doesn't work? I think I need to see the interaction blueprint for that.

        Also, sorry for the delay in response, I did not subscribe to the topic so I never saw you replied. I am subscribed now.

        Comment


          #5
          Originally posted by Chumble View Post
          I need some clarification on what is happening. This problem only exists with client 2, correct?

          So what it looks like from the blueprints you have

          1) Client 2 calculates its line trace in the world
          2) Client 2, on event tick, sends the start and end points from the line trace to the server
          3) The server then tells all clients to draw the line trace from the points sent from Client 2. At least I'm assuming that's what is happening in that "Interaction_Tracer" collapsed graph.

          Ok, so Client 2's line trace is being replicated across all clients, right? Looks like everyone can see Client 2 is aiming up. But the problem is when Client 2 tries to interact with something, it doesn't work?
          Exactly, because of that second trace thats beeing displayed.


          The interaction is quite simple. Its just an interface BP. The interaction works fine, if I place the object at the same high as the
          incorrect line trace.

          Attached Files

          Comment


            #6
            In multiplayer games pawn rotation is in most cases replicated which you can use for this purpose.
            What you should do instead is having a single replicated boolean which server sets and run client side logic to draw the line using pawn rotation whenever that boolean is set to true.

            Client presses button -> Server sets boolean -> All clients can now linetrace.

            This gets rid of multicast in tick (you should never need to do it like that and in general bad habit).

            Comment

            Working...
            X