diff --git a/Unreal/PS_AI_Agent/Plugins/PS_AI_ConvAgent/Source/PS_AI_ConvAgent/Private/PS_AI_ConvAgent_ElevenLabsComponent.cpp b/Unreal/PS_AI_Agent/Plugins/PS_AI_ConvAgent/Source/PS_AI_ConvAgent/Private/PS_AI_ConvAgent_ElevenLabsComponent.cpp index 24b134d..6001fb3 100644 --- a/Unreal/PS_AI_Agent/Plugins/PS_AI_ConvAgent/Source/PS_AI_ConvAgent/Private/PS_AI_ConvAgent_ElevenLabsComponent.cpp +++ b/Unreal/PS_AI_Agent/Plugins/PS_AI_ConvAgent/Source/PS_AI_ConvAgent/Private/PS_AI_ConvAgent_ElevenLabsComponent.cpp @@ -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(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 =