Replicated Linetrace Not Going Towards Center Of The Screen

Hi, I am making an ability only combat system and I have a few different abilities that use linetracing. This one in particular is suppose to go from the players chest to the center of the screen. The current system I have works fine until I try to replicate it. What ends up happening is the ability goes towards the center of the screen not only on P1’s screen but also the center of P2’s screen. In other words its running the trace and fx on both when only 1 does it. Additionally, replication of the ability doesn’t even work when trying on the client, replication only works on the server. So im not exactly sure how to go about this and have spent days looking online for solutions but I found nothing. I’ve attached a screenshot of the code for the linetrace.

For the server side you need to use:

Forward Vector: Pawn -> Get Base Aim Rotation -> Forward Vector
Camera Location: Player controller -> Camera Manager -> Get Camera Location

Highly recommend you stop using Get Player Character (index). The only time it’s even remotely suggested in multiplayer is in a Peer to Peer setup. aka Listen Server. Even then it’s not 100% reliable. Same applies for Get Player Controller (index).

For multiplayer you want to use Get Controlled Pawn and Get Controller.

More effective and reliable is using a fully casted reference variable.


Also, you want to get in the habit of using flow control to determine who can and does what and when.

Defining custom roles is a good way to handle it. Once you a have a role defined you can write custom functions and macros.

Hi! I’ve made said changes to my code and im still having the same issue. If it helps some extra info would be that the Trace Client event is a multicast (reliable) and the Trace Server event is of course run on the server (reliable).

Hi! I see that in addition to using the ThirdPersonCharacter you also use a seperate PC_ThirdPerson blueprint. Is this something I need to implement because as of now I only have 1 player blueprint and its the playable character.

What is “Dolt Snap BP” ? An Ability blueprint ?
If that is the case, there are several issues with your setup.

  1. You need to spawn it on server if you want any replication to happen. I assume you are testing in non-dedicated server mode so that’s why it replicates when called from P1 (host = server) but not from P2 (client). You cannot just spawn an actor on client-side and call server functions from it, the actor needs to originate from server. So whatever you are doing to spawn the ability (probably from Character or PlayerController), you must call a Run-on-Server function there to spawn the ability on server.

  2. When spawned on server, il will replicate to players, and each player will run BeginPlay code locally. Calling Trace Server from there, if it worked, would generate as many server & multicast calls as there are clients. Fortunately this doesn’t happen by design, because run-on-server calls are only allowed from clients that own the actor (or from server code). In your case you don’t need these calls anymore. Since each client runs BeginPlay locally, you can just trace from there. Basically, the replication of the actor itself replaces your multicast call.

  3. Right now, the only case that seemingly works for you is when ability is spawned from the host player (= server). As mentioned above, this is because when spawned from server, the ability will replicate to clients. Then server instance will run BeginPlay, which will be allowed to call run-on-server, which in turn will call Multicast for all clients. Now all clients are running “TraceClient”, but each of them is using GetPlayerCharacter(0). On clients, that node will return the local character, not the instigator of the ability. So each client runs a trace from its own chest. After fixing points 1 and 2, this will still happen. Instead of using GetPlayerCharacter(0) you need to pass down the instigator of the ability so clients can trace from him instead of themselves. To do this, you can use Owner or Instigator variables which are builtin all actors. Those variables are exposed to the SpawnActor node so you can just pass the responsible character there when spawning the ability in point 1. Then in TraceClient, use GetOwner or GetInstigator instead of GetPlayerCharacter(0).

Hi! I have made the changes you suggested to my code and the ability is now replicated when spawning from client and server however the issue of the linetrace going towards the center of the other players screen is still an issue. Should I remove the cast to (player actor) all together? Ive attached an image of my updated code inside of the Bolt Snap (Ability) actor blueprint.

Dont use the index based Gets!

image

Use Get Controller and Get Controlled Pawn in their respective classes. Then create a variable to store the obj reference.

Using the above imaged code:
TPP Player Controller -> Player Camera Manager -> Get Camera Location

Using the above imaged code:
Char Ref -> Get Base Aim Rotation -> Forward Vector


Pass the character reference to your Weapon/Ability. Using that reference you can get the controller var.

Hi. So that all makes sense but im a bit confused as to what the “PC_ThirdPerson” cast is. It looks to be a seperate character bp but I only have the one (players character).

PC_ThirdPerson is my Controller Class for my dev demo project. You should have a custom controller class. If you don’t then create one. You’ll need it.

My main game project has a core class for each main component.
Game Mode (GM), Game State (GS), Player Controller (PC), Player State (PS)

image


My character class references the controller class and player state regularly for varying things. Instead of constantly casting to them I create a variable for each, then use that variable.

Here’s my “current” dependencies polling function.

I call this function recursively via timer which is initialized on begin play in the character class.

So i need to create what is essentially a custom player controller for my player?

Yes, I edited my previous reply to show more of my code base.

Being technical you will want to have a custom game mode, game state, player controller and player state.

Okay so I have my own gamemode and player controller because of setting up multiplayer. I have an EOS_PlayerController and a EOS_SessionGamemode. Am I able to simply adjust these to my needs or do I need to make a completely different thing?

use the one that your Game Mode has as the Player Controller class.

image