UGameplayStatics::GetClosestListenerLocation
#include "Kismet/GameplayStatics.h"
Access: public
Specifiers: staticUFUNCTIONBlueprintCallable
Description
Finds the closest audio listener within MaximumRange of Location and writes its position to ListenerPosition. Returns false if no listener is within range or if the audio device is unavailable.
Caveats & Gotchas
- • Always returns false on a dedicated server or when no audio device exists. Never use the output ListenerPosition without checking the return value first.
- • The position returned is the listener's effective audio position, which may differ from the camera position when attenuation position overrides are active and bAllowAttenuationOverride is true.
Signature
static ENGINE_API bool GetClosestListenerLocation(const UObject* WorldContextObject, const FVector& Location, float MaximumRange, const bool bAllowAttenuationOverride, FVector& ListenerPosition); Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| WorldContextObject | const UObject* | Object used to retrieve the world context. | — |
| Location | const FVector& | World-space position from which to search for the nearest listener. | — |
| MaximumRange | float | Maximum search radius. Listeners beyond this distance are ignored. | — |
| bAllowAttenuationOverride | const bool | Whether to apply listener attenuation position overrides when computing the listener location. | — |
| ListenerPosition | FVector& | Output world-space position of the closest listener if found. | — |
Return Type
bool Example
Point an NPC toward the nearest listener C++
FVector ListenerPos;
if (UGameplayStatics::GetClosestListenerLocation(this, GetActorLocation(), 5000.f, false, ListenerPos))
{
FVector Direction = (ListenerPos - GetActorLocation()).GetSafeNormal();
// Use Direction for NPC attention behavior
} Version History
Introduced in: 4.0
| Version | Status | Notes |
|---|---|---|
| 5.6 | stable | — |
Feedback
Was this helpful?