Hello friends,
I am trying to figure out this multiplayer issue in my project.
In my pawn class, I have a server event to perform a line trace whenever the player clicks left mouse button.
This works fine for the player who is the listen server. But for the client, “Get Controller” is not returning the client’s controller. It’s returning the server’s controller.
How should I approach this? I tried getting the controller by player index but that did not work either.
Normally I would use “Get Player Controller” and not “Get Controller”, but I’m using primarily character and not pawn so idk if that will work the same. And if you’re running a server event straight off the bat it’s going to execute on all the clients, but as the server player controller…
I’m not sure what you’re trying to implement, but I usually create a custom event and mark it as “Multicast” and run your logic off of that node. Name it something like “LineTraceMulticast” Secondly create another custom event and call It “LineTraceServer” set it to run on server. Call the “LineTraceMulticast” from the server node. Call the server node from the pressed event.
Sometimes outside of lan connections you’d have to create another custom event that runs on owning client and connect it in tandem to where the Multicast logic begins and call it directly in front of or behind the server call off of the pressed. Or your client won’t know what’s going on… just what it’s seeing from the server… That scenario isn’t usually apparent in lan.
Taking a second look, with what I mentioned above I don’t think you can run a replicated function in a Multicast or run on server event like that. It would need to be in the pawn BP.
1 Like