Download

Networking & linetrace inconsistencies.

Hello there.

I’ve got some basic code to get the object a player is facing, then loop through any “Interactable” components it may have.

It works alright, until networking gets involved.

For some reason the line trace is incredibly inconsistent when ran on the server, I’m unable to figure out why or any patterns but in certain scenarios it just doesn’t work. It works on the client perfectly but the server is hit or miss.

Below is my code:

07dd4b4edd1023e73ad2ac511f4ecbbe7dba0f03.png

Any help would be very much appreciated.

My first thought would be the “first person camera” reference may be bringing the inconsistencies you are seeing. It is possible the server/client positions may differ which could be why it might be giving you different actors. Come to think of it, im not even sure if the camera is replicated/exists on the server…

Two things, you could try printing the forward vector and see if they are the same or slightly different. Second would be when calling the “What” event, to feed the server the Location/Forward Vector so you know the same variable are being used to calculate the trace.

Hope this helps!

is your rpc “reliable”? try to draw debug for duration and check where the trace goes in the certain scenarios you described

On server there is no first person camera. Unless it is listen server then you have camera but only for PlayerCharacter that hosts game.

I solved this different way:

  • i calculate beginning and end of trace in local, client player character.
  • then i do remote procedure call (ie event that runs on server), give it beginning and end then escalate to server.
  • then server side i do all traces.

You also should make check if you run really client code or mixed client server code when you have listen server.

If you want to make dedicated server, go for mixed listen server, but instead of default player controller and player pawn on listen server spawn some kind of spectator that lets you see what is going on. There are some amusing things in unreal when dealing with client, server and “listen server client”. You need to sort it all out (and understand) else it will confuse you forever.

ps. that whole thing of mixing code for client and server in same blueprint is very confusing.

Thanks, that was indeed it. I actually did try to do a debug draw and I did figure out that the forward vector was wrong (but not why), but I couldn’t see this post immediately after posting so I couldn’t delete it.

Yeah that’s purely debug code so I’m 100% sure it wasn’t me ******** up the code.