How to communicate between different blueprints in multiplayer?

Hey,

I feel like this is something simple I’m missing. I’m just trying to talk to different blueprints and trigger different events between them when running in multiplayer.

If all the functionality is in one BP or in the Level BP then everything works fine, but if I try and trigger an event in another blueprint it doesn’t play ball. I’ve attached screen shots of a very simple set up of events.

For example in the Level BP: Hit F which then calls an event on my ‘BP_AudioBaseActor’ and plays a sound.
The event in the ‘BP_AudioBaseActor’ is multicast and the actor is set to replicate.

I’ve also tried via an interface which doesn’t work (crossed that out in the picture)

However if all functionality is in one bp it has no issues communicating between server and client. E.g this works fine:

Anyone know what i’m missing or is this just not the way to do things?

Hi M.wmmn

When working with multiplayer, you have to think about your actor relationships differently.
Looking at your first screenshot, it seems you are trying to handle player input events from the level blueprints. Most player input events will fire on authority, but the level (owned by the server) won’t know exactly where these inputs are coming from.

Tldr: Move your inputs into the player controller or the pawn.

Now you are in your pawn/player controller, you need to make sure the actor itself is configured for replication.

271839-activatereplicated.png

Your second and third screenshot shows the event “AttemptPlaySound” is set to Multicast. Multicast events will only fire from serverside objects. Player controllers do have a server side, however, they are only relevant to themselves. This means one player controller cannot see another player controller.

Create an event in your Pawn “ServerPlaySound”. Event settings are “SERVER and reliable”.
Now add a multicast event “ReceivePlaySound”. Event settings are “MULTICAST and reliable”.

Make your ServerPlaySounds event call your ReceivePlaySound event.
On your ReceivePlaySound, do a switch has authority and on the remote pin, call the “Play” function on your audio clip.

Now just call the ServerPlaySounds event from a blueprint which allows input from a local controller.

My pawn

My world audio object

My results

Hope this helps! Good luck :slight_smile:

Ah right I see - thank you so much for your detailed and quick response! It helped a lot.

So if I wanted to then play the sound on the server as well as the client (e.g I wasn’t using a dedicated server) would any of the following approaches be viable or is there a better/different way?

1 - Including a separate ‘Audio Play’ call when the ‘ServerPlaySounds’ gets called:

Or 2 - Just wire up the ‘Has Authority’ node to the ‘Audio Play’ function too

Thanks again!

Multicast events will also get invoked on the listen-server. SwitchHasAuthority is just a filter so you can remove that from option 2 since you want the sound on all.

I am glad you found my information useful. These things can be hard to explain.

Your first screenshot in your reply is correct. If you want to call an event, function or change an object state on the server, anything after a SERVER RPC will handle that.

I am not sure why you would want to play audio on a server. Even if you are using a “listen server”, the host will still have a remote (client) side which will handle playing audio. The server should be used to hold the states of objects and distribute information between clients. It shouldn’t have the need for client outputs such as audio, particles, UI elements etc. Because you should treat the server as king, you want to remove any unnecessary processing.

I admit, I only really work with dedicated servers, so maybe listen servers have a need for it. My advice would be to ensure that all your function calls on the server are required.

Good luck with your project! :slight_smile: