Download

Run logic on actor PlaySound()

I’m building a underground cave system and I’d like to be able to prevent sounds that are emitted from above ground level from playing for players that are in caves.

Does calling PlaySound() on an actor result in another script function being called? So I can handle the various conditions of whether the sound should be audible or not?

I wont be of any help for this but isn’t it as simple as just setting the sound radius in the sound cue editor?

@O_and_N Unfortunately not. My gunshot sounds have a very large radius. I need to be able to run some logic each time a sound cue attempts to play. I can’t see any sound cue nodes that call script.

/* * Play a sound. Creates an AudioComponent only if the sound is determined to be audible, and replicates the sound to clients based on optional flags *
@param InSoundCue - the sound to play *
@param bNotReplicated (opt) - sound is considered only for players on this machine (supercedes other flags) *
@param bNoRepToOwner (opt) - sound is not replicated to the Owner of this Actor (typically for Inventory sounds) *
@param bStopWhenOwnerDestroyed (opt) - whether the sound should cut out early if the playing Actor is destroyed *
@param SoundLocation (opt) - alternate location to play the sound instead of this Actor’s Location *
@param bNoRepToRelevant (opt) - sound is not replicated to clients for which this Actor is relevant (for important sounds that are locally simulated when possible) */

native noexport final function PlaySound(SoundCue InSoundCue, optional bool bNotReplicated, optional bool bNoRepToOwner, optional bool bStopWhenOwnerDestroyed, optional vector SoundLocation, optional bool bNoRepToRelevant);

Hope this helps.

@gamepainters But there is no way to extend this function as it is a native final function.

Found it (in PlayerController)!



/* ClientHearSound()
Replicated function from server for replicating audible sounds played on server
*/
unreliable client event ClientHearSound(SoundCue ASound, Actor SourceActor, vector SourceLocation, bool bStopWhenOwnerDestroyed, optional bool bIsOccluded )


This looks like it runs for all sounds (even in single player and as the server). This is awesome, now I can occlude sounds based on my own logic :slight_smile:

Thanks for the input guys.