I have a question regarding sound replication. Is there a way to make a player not hear a sound he is producing but that other clients can hear? I’m guessing that even if I call a Run On Server function I will still be able to hear the sound produced. The context in which I’m trying to execute this is a first person game. So the steps in First Person go at a different rate than ones of the full body animation. My mental attempt was to make a Run on Client function and play the sound from there for the first person but I’ll still be able to hear the sounds that I would be triggering through Anim Notifies from the fullbody animations.
Any thoughts on this would be greatly appreciated !
One common method is to create a custom Sound Cue node that will handle this.
The ShooterGame demo has a class called SoundNodeLocalPlayer that plays a stereo sound for the client and a mono sound that will be spatialized property for other clients. You could use this node to not only play a mono sound, but play a different sound altogether (as technically the mono sound is already a different sound)
This approach would work with AnimNotifies as an AnimNotify just takes a SoundCue, and this implementation would be part of the SoundCue itself.
If you’re using Blueprint…
You can create a multicast event that will play sounds when called. In that event, do a check to see if the pawn is controlled by a local player controller. If it is, play your local sound, if its not, play your networked sound. Then replicate the function call. A multicast event must be called from the server, so if you have to start this logic from a client, then make a second event with replication Run On Server that would call the Multicast event.
Heyy !! Thanks for the quick answer. I would be using blueprint. So that function call, where would it be called from ? Wouldn’t it always be locally controlled ? (not a networking engineer as I’m sure you could tell haha).
I suppose Events is the more correct term. You can set up an event to Multicast and then call that event when you want to play the sound.This would have to be called from the server. If you want to call this chain from the owning client instead, you can have a second event that will call Run On Server which will then call the Multicast. You can also try to use a RepNotify variable as well.
If you put these functions in your Character class, when the server runs the multicast it will be ran on Character that the footstep is to be played on, which includes both your locally controlled and other non locally controlled characters.
Ahhh yes. So starting from the Character class I call “run on server”, multicast, check for “Is locally controlled” then play the sound. Brilliant ! Thanks a whole lot.
Yep everything works perfecto ! Thanks to @Allar. Well… he definitely laid it out for you. Just follow what he says and you’ll definitely get it.
If you want to replicate a sound to everybody from a client… make him trigger a run on server function that calls a multicast then from there play the sound. If you don’t want the owner to hear the sound triggered by him, before you play the sound from the multicast make a check with the node “is locally controlled”. If it’s false then play your sound. That way only clients that are not locally controlled (i.e. not you) will execute the code.
thanks for your answer. but i have a little question about how play the sound? i should use “play sound at location” or “play sound attached” ? sorry for being so annoying thanks