Download

How can I play player-specific sounds in online multiplayer?

I know this sounds like a “just use Play Sound 2D since it’s (supposedly) supposed to play on the clients only” but that doesn’t work. I have a handful of player-specific sound effects that shouldn’t be replicated to other clients, but they totally are and I am at a loss after having tried/searched for almost everything.

They aren’t using any replicated events at all. I’ve put the 2D and Play at Location Play Sound events in the character itself, or cast to the Player Controller, or played directly from the controller since it should only belong to the owning player but no luck. When I play a specific sound that’s meant ONLY for the owning client, it plays on every networked player, every time.

What is the trick? Is this a bug? How can I have specific sounds play ONLY on my networked player’s client? (They are sounds like getting hit, “danger” for low health, “you have 10 seconds to do x”, etc.)

Here is more info and a pic of what’s working for ALL clients EXCEPT the listen server player.

I have 8 players in my multiplayer game. Everything works as intended (gameplay, variables, VFX, server travel, player possession) by only using Blueprints and audio is my only remaining hurdle.

I have been so close to getting everything to work as intended by calling sounds straight from the character/Player controller blueprint by getting the controller in my character blueprint and casting to my player controller blueprint where I then call a custom event to connect to the correct sound.

This works on all 7 clients - meaning the player-only sounds play correctly on their respective machines - but NOT on the host/listen server player. When I try to cast to my player controller blueprint, the cast fails if the player is the listen server.

I feel like if I can find that ONE right check to do for that host/listen server player and then play sounds it should work. But even dragging off “failed” on my cast to play a sound plays on all players.

So before I dig into making my own BP struct for each sound effect (which I’m still a little fuzzy on how exactly to do that in BP), do I sound close enough to getting it in my character blueprint?

Last item of note: when I play sound off of an input action on my character Blueprint, it works perfectly on all players. No casting needed. No work-arounds. It just…works. (Like when it’s in a chain initialized by the fire button input event or pressing any key/gamepad button event.) All of my issues here are resulting from being initialized by Event Begin Play or Event Hit.

blueprint.png

Hello, first of all I think you are overcomplicating things. Take a look at this example I made for you:

2EUDtW6.jpg

For the sake of the example, the user needs to press “O”, well in your case you don’t have to. Check how the server sends a packet to the client, to play a sound. You don’t need a custom event for each sound, you just add an argument as to which file to play.
Also, as you can see I made the event to run on the owning client. So, you get the player controller from the player that you want to hear the sound, and execute the Play Sound event, and select which file to play. I hope you understand what I mean :slight_smile:

I do! My thing is that casting to the PlayerController fails off of BeginPlay if it’s the listen server player. Everything works fine if it’s the client. That said, your setup is something I haven’t quite tried yet so I will give it a shot regardless! Thanks for this!

And just as I hoped, I wouldn’t need to even cast to the playercontroller to get this to work. This is all now contained within the character blueprint. This double custom event approach first as a server call leading to an owning client call works PERFECTLY! Thank you DjSt3rios!

Edit: Added pic of what’s working in my character blueprint for good measure. It’s like audio laundering.

multiplayermakesoundsworkforclientonly.png

You are welcome :slight_smile: I am glad you got it working.
I should also mention, in your character, in begin play you should add a check if it’s the server, then play the sounds, and maybe even the emitter (not sure if it’s replicated).