LineTrace on Server from pawn

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.