RealDocs

UGameplayStatics::AreAnyListenersWithinRange

function Engine Blueprint Since 4.0
#include "Kismet/GameplayStatics.h"
Access: public Specifiers: staticUFUNCTIONBlueprintCallable

Description

Returns true if at least one audio listener (typically the player camera) is within MaximumRange of Location. Use this to cheaply cull sound spawns that no one would hear.

Caveats & Gotchas

  • Always returns false if there is no audio device or the audio device is disabled (e.g., -nosound command line flag, or dedicated server). Guard with a fallback if you rely on this for gameplay logic, not just audio culling.
  • In splitscreen, each local player has a separate listener — this returns true if any of them is in range, not all of them.

Signature

static ENGINE_API bool AreAnyListenersWithinRange(const UObject* WorldContextObject, const FVector& Location, float MaximumRange);

Parameters

Name Type Description Default
WorldContextObject const UObject* Object used to retrieve the world context.
Location const FVector& World-space position to test against listener positions.
MaximumRange float Maximum distance at which a listener is considered in range.

Return Type

bool

Example

Skip spawning ambient sound no one can hear C++
if (UGameplayStatics::AreAnyListenersWithinRange(this, GetActorLocation(), 2000.f))
{
    UGameplayStatics::PlaySoundAtLocation(this, AmbientSound, GetActorLocation());
}

Version History

Introduced in: 4.0

Version Status Notes
5.6 stable

Feedback

Was this helpful?

Suggest an edit

Select a field above to begin editing.