Playing a sound at location from a widget button on multiplayer.

Hey! I am making a pretty social game which includes instruments.
One of these is a guitar which is controller in the widget blueprint.
Now recentely I have upgraded to lan multiplayer for playing this game with my friends.
How would I go about clicking a button on a widget to playing that audio near me for everyone to hear.
I have already tried things I found on forums but just never got it to work.
This is just kinda my last resort.
Thanks in advance!

Hey !

Sorry to hear that you’re having issues getting everything working! First, I had a couple of questions regarding your setup that might help me get a better idea of exactly what is happening so I can get you exact steps.

  1. How are you creating the widget for input?
  2. Does your widget have a reference to the guitar or player?

Regardless of the setup my best recommendation is to set up custom events to Multicast the sounds you want to play. I highly recommend putting the events in the Guitar’s logic and calling the event from the widget as needed, but depending on your setup, it might be difficult to get the reference to the Guitar to the widget so you can put the events in the player if it comes to that. (You can always get player and controller by getting OwningPlayer or OwningPlayerPawn in a widget.)

Step by step I’d say:

  1. Open Guitar or player and create a multicast custom event named CLI_PlayGuitarSound (or whatever you want) and pass whichever parameters you need to pass through (i.e. passing the PlaySoundAtLocation location and sound parameters from the event to the function)
  2. Open your widget logic and get a reference to the object that holds the play sound logic.
  3. OnButtonClick->CLI_PlayGuitarSound(plus whatever parameters you need)

Standard practices state that you should only run ambient effect logic on the client (i.e setting locations/rotations/scale or playing sounds or particles.) IMO everything else should be handled by the server to help with security and replication. To avoid issues I run all traces, set all vars and run any other complex calculation on the server, then replicate the results to the client using custom events. If you happen to need to do anything else to calculate what sound to play or where to play the sound, I highly recommend creating a custom event run on the server that calls the event on the client after all calculations have been performed.

I can take some screenshots here in a second. I’m just getting my project loaded right now so I’ll have the editor up in about 20 minutes to help!

I wish you the best!