I’m trying to play simple SoundCue. But sometimes it is not working. I debugged code and I think found the problem.
When I calling SpawnSoundAttached with KeepRelativeOffset IsAudibleSimple returning false and my sound is not playing.
// Location used to check whether to create a component if out of range
FVector TestLocation = Location;
if (LocationType != EAttachLocation::KeepWorldPosition)
{
TestLocation = AttachToComponent->GetRelativeTransform().TransformPosition(Location);
}
UAudioComponent* AudioComponent = FAudioDevice::CreateComponent(Sound, AttachToComponent->GetWorld(), AttachToComponent->GetOwner(), false, bStopWhenAttachedToDestroyed, &TestLocation, AttenuationSettings);
if (AudioComponent)
{
Here you can see, FAudioDevice::CreateComponent getting Relative TestLocation instead of World and inside this function “IsAudibleSimple” calling with RelativeLocation instead of WorldLocation.
Just so I understand clearly, is the issue that the sound isn’t playing or that it is not being played in the correct location? Is the code you posted part of the source or is it your own code? Where is this being called from? Are you able to reproduce the issue in a new project without additional content? If so can you post the steps that reproduced this for you?
Oh I forgot important thing. Your Sound duration should be less than 1 seconds. If your sound greater than 1seconds it is working fine because IsAudible forcing to true if duration greater than 1seconds
So running some test with your set up, I think I found the source of your issue. I was able to reproduce what you are reporting, using the Spawn Sound Attached node in blueprints at the location 50,000x50,000x50,000, and playing a sound less than 1 second.
Be sure your sound does not have attenuation settings applied (Untick Attenuate). See the below images for reference.
As soon as I checked the ‘Attenuate’ option on the Sound Cue I am unable to hear the sound upon pressing play in my level. However, if I uncheck ‘Attenuate’ within the ‘Sound Cue’, the sound plays just fine.