LineTrace on Server from pawn

Hi!

I have a simple line trace from my camera (using it to rotate attached weapons) , works on client, how do I get it to work on the sever side so/or it gets replicated to other clients/actors?
The numbers on the sever side are totally wonky :confused:
I have tried to put the event to Run on server, Multicast /Switch Authority nothing works!

8973bb2e431c9a092a638de7a5f9361b01330eea.jpeg

Or I think I’m after replicating the spring arm!

I think camera location is not replicated to server, its your client thing only.

Make server side event where you feed camera location to server.
Call it from player controller (or pawn) set last tick camera location and rotation.

Then trace on server (behind authority gate).

Another culprit herer may be fact you are using references to camera, they do not transfer at all over to another client or server (because they are in different processes/pcs, so their pointers are totally different). And that reference to camera may be invalid on server. Well this again goes back to fact that camera is not replicated.

Ps.
For getting forward vector use: reference then get forward vector out of it you do not need to use rotation as middle men.

It just like the control or camera variables has locks on em (ā€œoh you are trying to get pass values that comes from control or camera to the server , screw you !!!ā€ )

Well i was (quite recently) trying to get how that whole replication works, epic tutorials do not mention lots of tiny details.
For eg. variables are replicated FROM server TO client, never from client to server.
To get your client variables into server you must create event that is run server side, then call that event and sent variables from client to server.

In your case:

  • do line trace client side (because it knows camera pointer and camera exists for player on client)
  • store whatever you want from trace results in client side variable
  • create server side variable that are replicated and correspondent to client side
  • then create event that runs server side, and its whole purpose is to set those server side variables.
  • after trace on client, call that server side event , and feed it with client side variables

There may be better way to communicate with server, but i haven’t find it yet.

Also because of my game setup, all my code runs in two layers.

  • everything that is player input and camera is on client in player controller, and it sends all data to game state only
  • game state has all that events that communicate up from client to server, because game state is replicated by default and has easiest way to find reference ever for all clients etc. This is like only one reference that i know that works everywhere without hassle.
  • then game state sets and replicates all variables after processing input.

Making game state middle man and brain for everything solves lots of problems.

On top of above i made several blueprint actor components that are crafted for game state only (cast to BP_MyGameState, and expect game state to be owner). I split all code into those components so all logic is kept in separate containers, i hate to have all blueprints cluttering single graph.

Ye its rather tricky stuff replication, I’m learning too. I do get in trouble every time I try to do something that has to do with the camera/springarm.

This is my set up and if I just get the CenterScreenLT vector to get ā€œthroughā€ I’m a happy. I’m working on a prototype so getting it ā€œright and cheat safeā€ isn’t important right now.

For some reason it want work??

That center screen LT is not replicated variable, it only exists on that client (or has different values on different clients).
You need to tell server side what value of that ā€œcenter screen LTā€ is, then replicate it back to everybody, or to server side of your blueprint.

Server side and client side of same blueprint seemingly in same actor, in fact are in two different actors on 2 different machines.

Your client machine needs tell server machine that this variable is changed and its current value.
Then server sends it back to that actor copy on every replicated client. Including one that sent updated value

Best way to avoid confusion here, is to create same variables for client and server, and have those client and server words in their names)

So calculate CLIENT: center_screen_LT
feed it to custom event that runs on server, it will transmit that value over to server pc
on server side of that custom event store value in ā€œSERVER: center_screen_LTā€
then set that variable to replicated
and use it (replicated variable) to do whatever you want back on client side. This way every client will have same value for that actor.

Like this?

With this the server gets updated and the bullets hits where I aim on server and clients , all weapons rotate on server, only server (listen server) rotates on clients, no rotation on client or client to client.

Upps! Noticed that I missed to replace one in the GetCameraLineTrace function, didn’t make any difference anyway, same result.

Thanks ! Finally got it to work :slight_smile: