How to synchronize functions & events over network?

Right now my team is developing a coop game with internet connection. The thing that bothers us the most is networking synchronization. For example, we have a flashlight mechanic in the game where each player will have its personal flashlight and whenever the player holds a button, his/her flashlight activates. We don’t want the button press from 1 player affect others’ flashlights but at the same time others should be able to see his flashlight if it’s activated. We tried a lot of approaches but they did not work. This is the current workaround solution we have so far.

As you can see, this is extremely ugly (and probably very low effective as well). I think there should be better solutions for this situation but we couldn’t find or come up with any right now. There are lots of places where we had to do this ugly thing right now. Could anyone point us to the right direction about how to change the structure so that I don’t have to use thousands of Switch Has Authority in our game but we can still achieve the same functionality? Thanks.

Multicast is there for these kind of things, I think.

We have tried only using multicast, but the client side doesn’t update.

The basic networking pattern that you want to follow is to RPC input events up to the server, have the server change state variables, and then setup those state variables to replicate back to all clients. In your case you would do the following:

Capture the input event in the Character or Player Controller (client side).
Call a Run at Server RPC function to pass the input to the server.
On the server side, toggle a bool state variable in your Character BP that keeps track of whether the flashlight is on or off.
Set this bool state variable to replicate with a rep notify. This will create a RepNotify function for you in your Character BP.
This RepNotify function will be called on all clients whenever the value of the bool state variable changes on the server.
Inside the RepNotify function, toggle the state of your light based on the incoming value of the bool state variable. This will ensure that even players that connect to your game late will always get the proper flashlight on/off state.

The other common networking pattern is to use a multicast, but it is not appropriate in your case. Whenever state is permanently changed, you want to use the pattern I outlined above. My rule of thumb is that any effect that lasts for more than a second or two should use replicated variables instead of a multicast pattern.