Linetrace not hitting anything when replicated

I’ve spent at least a week trying to get this to work and pretty much given up. It works fine offline and when there’s a listen server involved, but whenever its just two clients the line trace either doesn’t fire or doesn’t hit anything, and I cant figure out which.

Video Demonstrating Problem
2022-04-18 16-10-56.mkv (11.0 MB)


There is no line trace in your screenshot. But if the line trace is inside of your OnFire event it will probably only be called on the server and therefore you will not see it on a client if you are using the DrawDebugType enum. If the line trace is colliding with something it is probably your character or the weapon.

Also remember that the multicast event fires on all clients and the server. If the OnFire event also calls the MulticastFire event you are causing some unwanted loop behaviour.

in case you didn’t see, there’s also a video demonstrating the problem. The on fire function containing the line trace is only replicated on the server and its suppose to ignore the character. Also when testing offline the line trace works as intended.

On Fire Fuction bottom to top: (sorry coudnt fit into a single screen shot)

Yea i missed your video.
But the video shows that the line trace does not hit anything as it prints out nothing.
My guess is that your weapon property is only set on the client and therefore is not replicated to the server. Resulting in a linetrace of length 0 as the start and end position are both the 0 Vector which leads to the trace never hitting anything.

What you have to know here is that replication for variable only works from the server to the client. If you set a replicated variable on the client it will not replicate to the server (what i think you are doing).

To set the variable from the client you have to do somethin like that:

So I did some testing and the end and start vectors work fine, its just the location output is zero. But the weird thing is on one part of the wall everything works as intended except for the impact particle spawning, and now I’m even more confused

Video Demonstration
2022-04-19 16-02-12.mkv (15.6 MB)

Init Weapon

Sorry dude but your code is a mess.

You can not multicast from the client which underlines my theory from before that you only set your weapon on the client or ther server has a the same value set to a different gun or something. Would be interesting what your InitWeapon does.

PS: a valid check is useless if you ignore it anyway

Yeah sorry for my code being such a mess, its been though a lot of jank and quick bug fixing and never really cleaned it up.

Init Weapon Function:

its possible that the problem stems from the spawning of the weapon but I think it may have something to do with the colliders, because as I showed in the 2nd video, certain parts of the wall do register in the line trace

Ok this confirms that you are spawning and setting the weapon only on the client as the init event is only called from the client as far as i can see it.

I recommend you to make sure that your weapon actor has the replicated bool checked and then only execute the init weapon event on the server by changing your “ServerInitWeapon” event from multicast to server.

I don’t know why the trace is hitting only some walls but i think it is because the clients representation of the weapon does not equal the servers representation.

I tried setting init weapon server to replicate on server and it still comes out with the same issue. Weapon is replicated. I also printed some values and found out that the distance was zero, implying intial overlap, but the time was 1, implying there was no collision. it would be really nice if there was a way to see replicated line traces so i could figure out whats going on.

You kind of can. Just wire a drawDebugLine from gun socket location to linetrace starting location and another drawDebugLine from gun socket location to linetrace target location. And make the render duration linger a while. DrawDebug nodes are handy.

As to your issue, If this is really a collision issue, you might have to disable collision on your weapon so the trace can run through.