Enable audio spatialization by default for agent voice
- Attach AudioPlaybackComponent to owner's root component for proper 3D world positioning (was unattached = stuck at origin) - Enable default inline spatialization with 15m falloff distance when no external SoundAttenuation asset is set - External SoundAttenuation asset still overrides the default if set Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
76dd13944a
commit
3952847ece
@ -1004,20 +1004,38 @@ void UPS_AI_ConvAgent_ElevenLabsComponent::InitAudioPlayback()
|
||||
ProceduralSoundWave->SoundGroup = SOUNDGROUP_Voice;
|
||||
ProceduralSoundWave->bLooping = false;
|
||||
|
||||
// Create the audio component attached to the owner.
|
||||
// Create the audio component and attach to the owner's root for proper
|
||||
// world positioning (required for 3D spatialization).
|
||||
AudioPlaybackComponent = NewObject<UAudioComponent>(Owner, TEXT("PS_AI_ConvAgent_Audio_ElevenLabsPlayback"));
|
||||
AudioPlaybackComponent->RegisterComponent();
|
||||
if (USceneComponent* Root = Owner->GetRootComponent())
|
||||
{
|
||||
AudioPlaybackComponent->AttachToComponent(Root,
|
||||
FAttachmentTransformRules::SnapToTargetNotIncludingScale);
|
||||
}
|
||||
AudioPlaybackComponent->bAutoActivate = false;
|
||||
AudioPlaybackComponent->SetSound(ProceduralSoundWave);
|
||||
|
||||
// Spatialization: if an attenuation asset is set, enable 3D audio so the
|
||||
// agent's voice attenuates with distance and pans spatially for the listener.
|
||||
// Spatialization: enable 3D audio so the agent's voice pans and
|
||||
// attenuates based on distance and direction from the listener.
|
||||
if (SoundAttenuation)
|
||||
{
|
||||
// Use the externally authored attenuation asset.
|
||||
AudioPlaybackComponent->AttenuationSettings = SoundAttenuation;
|
||||
AudioPlaybackComponent->bOverrideAttenuation = false;
|
||||
AudioPlaybackComponent->bAllowSpatialization = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Default spatialization with inline attenuation — works out of the box.
|
||||
// Override with an external SoundAttenuation asset for fine-tuning.
|
||||
AudioPlaybackComponent->bAllowSpatialization = true;
|
||||
AudioPlaybackComponent->bOverrideAttenuation = true;
|
||||
FSoundAttenuationSettings& Att = AudioPlaybackComponent->AttenuationOverrides;
|
||||
Att.bAttenuate = true;
|
||||
Att.bSpatialize = true;
|
||||
Att.FalloffDistance = 1500.0f; // Full attenuation over 15 meters.
|
||||
}
|
||||
|
||||
// When the procedural sound wave needs more audio data, pull from our queue.
|
||||
ProceduralSoundWave->OnSoundWaveProceduralUnderflow =
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user