From 301efee982a0dbd5399466d04ea15d7f3202fbf8 Mon Sep 17 00:00:00 2001 From: "j.foucher" Date: Fri, 27 Feb 2026 18:33:08 +0100 Subject: [PATCH] Enable body tracking on both voice and text input Body tracking is now activated by ElevenLabsComponent directly in StartListening() and SendTextMessage(), instead of being managed by InteractionComponent. This ensures the agent turns its body toward the player on any form of conversation input. InteractionComponent still disables body tracking on deselection. Co-Authored-By: Claude Opus 4.6 --- .../PS_AI_ConvAgent_ElevenLabsComponent.cpp | 23 +++++++++++++++++++ .../PS_AI_ConvAgent_InteractionComponent.cpp | 13 +++++------ 2 files changed, 29 insertions(+), 7 deletions(-) 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 20b0435..7dbcb4c 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 @@ -2,6 +2,7 @@ #include "PS_AI_ConvAgent_ElevenLabsComponent.h" #include "PS_AI_ConvAgent_MicrophoneCaptureComponent.h" +#include "PS_AI_ConvAgent_PostureComponent.h" #include "PS_AI_ConvAgent_InteractionSubsystem.h" #include "PS_AI_ConvAgent.h" @@ -312,6 +313,17 @@ void UPS_AI_ConvAgent_ElevenLabsComponent::StartListening() Mic->StartCapture(); } + // Enable body tracking on the sibling PostureComponent (if present). + // Voice input counts as conversation engagement, same as text. + if (AActor* OwnerActor = GetOwner()) + { + if (UPS_AI_ConvAgent_PostureComponent* Posture = + OwnerActor->FindComponentByClass()) + { + Posture->bEnableBodyTracking = true; + } + } + const double T = TurnStartTime - SessionStartTime; UE_LOG(LogPS_AI_ConvAgent_ElevenLabs, Log, TEXT("[T+%.2fs] [Turn %d] Mic opened%s — user speaking."), T, TurnIndex, bExternalMicManagement ? TEXT(" (external)") : TEXT("")); @@ -404,6 +416,17 @@ void UPS_AI_ConvAgent_ElevenLabsComponent::SendTextMessage(const FString& Text) return; } WebSocketProxy->SendTextMessage(Text); + + // Enable body tracking on the sibling PostureComponent (if present). + // Text input counts as conversation engagement, same as voice. + if (AActor* Owner = GetOwner()) + { + if (UPS_AI_ConvAgent_PostureComponent* Posture = + Owner->FindComponentByClass()) + { + Posture->bEnableBodyTracking = true; + } + } } void UPS_AI_ConvAgent_ElevenLabsComponent::InterruptAgent() diff --git a/Unreal/PS_AI_Agent/Plugins/PS_AI_ConvAgent/Source/PS_AI_ConvAgent/Private/PS_AI_ConvAgent_InteractionComponent.cpp b/Unreal/PS_AI_Agent/Plugins/PS_AI_ConvAgent/Source/PS_AI_ConvAgent/Private/PS_AI_ConvAgent_InteractionComponent.cpp index 1344381..597eab3 100644 --- a/Unreal/PS_AI_Agent/Plugins/PS_AI_ConvAgent/Source/PS_AI_ConvAgent/Private/PS_AI_ConvAgent_InteractionComponent.cpp +++ b/Unreal/PS_AI_Agent/Plugins/PS_AI_ConvAgent/Source/PS_AI_ConvAgent/Private/PS_AI_ConvAgent_InteractionComponent.cpp @@ -198,8 +198,11 @@ void UPS_AI_ConvAgent_InteractionComponent::SetSelectedAgent(UPS_AI_ConvAgent_El if (bAutoManageListening) { OldAgent->StopListening(); + } - // Disable body tracking — eyes+head will return to neutral via posture detach. + // Disable body tracking on deselection. + if (bAutoManagePosture) + { if (UPS_AI_ConvAgent_PostureComponent* Posture = FindPostureOnAgent(OldAgent)) { Posture->bEnableBodyTracking = false; @@ -247,15 +250,11 @@ void UPS_AI_ConvAgent_InteractionComponent::SetSelectedAgent(UPS_AI_ConvAgent_El } // ── Listening: start ───────────────────────────────────────────── + // Body tracking is enabled by ElevenLabsComponent itself (in StartListening + // and SendTextMessage) so it works for both voice and text input. if (bAutoManageListening) { NewAgent->StartListening(); - - // Now that we're talking, enable full body tracking. - if (UPS_AI_ConvAgent_PostureComponent* Posture = FindPostureOnAgent(NewAgent)) - { - Posture->bEnableBodyTracking = true; - } } // ── Posture: attach ──────────────────────────────────────────────