From 1ef457ed011a3d5d65021d403ec7731ae1fe63fd Mon Sep 17 00:00:00 2001 From: Mohcine Chraibi Date: Tue, 11 Aug 2026 19:29:09 +0200 Subject: [PATCH] fix(mass): make agent click-selection work Agent selection (red button, then click a pedestrian) never worked because UDisableCollisionSignalProcessor was subscribed to the ActivateCollisions signal as well as DeactivateCollisions - the very signal that enables selection also re-disabled it in the same frame, so the pedestrian hit-capsules never activated and the selection trace could not hit anything. Drop the wrong subscription; the existing "feels wrong" comment on it was right. Route plain left-clicks into the C++ selection trace from the controller (the BP click path proved unreliable), add a MobiusActivateCollisions console fallback for the red button, a MobiusToggleClickSelect escape hatch, and log the value passed to CollisionsSettingChanged. Known limitation, unchanged: ActivateCollisions is a silent no-op when pressed before any agents have spawned. --- .../Private/Controller/MobiusController.cpp | 29 +++++++++++++++++++ .../EnableCollisionSignalProcessor.cpp | 4 ++- .../SubSystems/PedestrianSignalSubsystem.cpp | 2 +- .../Public/Controller/MobiusController.h | 10 +++++++ 4 files changed, 43 insertions(+), 2 deletions(-) diff --git a/UnrealFolder/ProjectMobius/Source/ProjectMobius/Private/Controller/MobiusController.cpp b/UnrealFolder/ProjectMobius/Source/ProjectMobius/Private/Controller/MobiusController.cpp index 8aef410dc..832657834 100644 --- a/UnrealFolder/ProjectMobius/Source/ProjectMobius/Private/Controller/MobiusController.cpp +++ b/UnrealFolder/ProjectMobius/Source/ProjectMobius/Private/Controller/MobiusController.cpp @@ -29,6 +29,7 @@ #include "IXRTrackingSystem.h" #include "GameInstances/ProjectMobiusGameInstance.h" #include "Subsystems/MobiusControllerSubsystem.h" +#include "MassAI/SubSystems/PedestrianSignalSubsystem.h" #include "SubSystems/TimeDilationSubSystem.h" #include "Subsystems/MobiusUserFeedbackSubsystem.h" #include "Util/FrameGrabberHelper.h" @@ -110,6 +111,16 @@ void AMobiusController::Tick(float DeltaTime) { FrameGrabberHelper->Tick(DeltaTime); } + + // Native click-to-select: runs the same trace the BP click path should trigger. + // Selecting is a no-op until collisions are activated, so this is safe by default. + if (bClickSelectsAgent && WasInputKeyJustPressed(EKeys::LeftMouseButton)) + { + if (UMobiusControllerSubsystem* ControllerSub = GetWorld()->GetSubsystem()) + { + ControllerSub->SelectPedestrianFromMousePosition(); + } + } } void AMobiusController::GetScreenshotRequiredSubsystemsAndData() @@ -498,6 +509,24 @@ void AMobiusController::InterpolateCameraToTransform(const FTransform& TargetTra } } +void AMobiusController::MobiusActivateCollisions() +{ + if (UPedestrianSignalSubsystem* SignalSub = GetWorld()->GetSubsystem()) + { + UE_LOG(LogTemp, Display, TEXT("MobiusActivateCollisions: firing CollisionsSettingChanged(1)")); + SignalSub->CollisionsSettingChanged(1); + } + else + { + UE_LOG(LogTemp, Warning, TEXT("MobiusActivateCollisions: PedestrianSignalSubsystem not found")); + } +} + +void AMobiusController::MobiusToggleClickSelect() +{ + bClickSelectsAgent = !bClickSelectsAgent; + UE_LOG(LogTemp, Display, TEXT("Native click-select: %s"), bClickSelectsAgent ? TEXT("on") : TEXT("off")); +} void AMobiusController::CycleCameraSavePoints() { diff --git a/UnrealFolder/ProjectMobius/Source/ProjectMobius/Private/MassAI/SignalProcessors/EnableCollisionSignalProcessor.cpp b/UnrealFolder/ProjectMobius/Source/ProjectMobius/Private/MassAI/SignalProcessors/EnableCollisionSignalProcessor.cpp index 9da7a3701..92c479eaf 100644 --- a/UnrealFolder/ProjectMobius/Source/ProjectMobius/Private/MassAI/SignalProcessors/EnableCollisionSignalProcessor.cpp +++ b/UnrealFolder/ProjectMobius/Source/ProjectMobius/Private/MassAI/SignalProcessors/EnableCollisionSignalProcessor.cpp @@ -63,7 +63,9 @@ void UDisableCollisionSignalProcessor::Initialize(UObject& Owner) { // Subscribe to the signals we want to handle in this processor UMassSignalSubsystem* SignalSubsystem = UWorld::GetSubsystem(Owner.GetWorld()); - SubscribeToSignal(*SignalSubsystem, PedestrianDataSignals::Signals::ActivateCollisions);// check that this is needed feels wrong + // Only DeactivateCollisions: subscribing to ActivateCollisions as well made this + // processor re-disable the entities the enable processor had just enabled, so the + // collision capsules never activated and agent selection always missed. SubscribeToSignal(*SignalSubsystem, PedestrianDataSignals::Signals::DeactivateCollisions); Super::Initialize(Owner); } diff --git a/UnrealFolder/ProjectMobius/Source/ProjectMobius/Private/MassAI/SubSystems/PedestrianSignalSubsystem.cpp b/UnrealFolder/ProjectMobius/Source/ProjectMobius/Private/MassAI/SubSystems/PedestrianSignalSubsystem.cpp index 047bb4dda..432ab7efb 100644 --- a/UnrealFolder/ProjectMobius/Source/ProjectMobius/Private/MassAI/SubSystems/PedestrianSignalSubsystem.cpp +++ b/UnrealFolder/ProjectMobius/Source/ProjectMobius/Private/MassAI/SubSystems/PedestrianSignalSubsystem.cpp @@ -24,7 +24,7 @@ UMassEntitySpawnSubsystem* UPedestrianSignalSubsystem::GetSpawnSubsystem() void UPedestrianSignalSubsystem::CollisionsSettingChanged(uint8 EnableDisable) { - UE_LOG(LogTemp, Display, TEXT("Pedestrian CollisionsSettingChanged")); + UE_LOG(LogTemp, Display, TEXT("Pedestrian CollisionsSettingChanged value=%d"), EnableDisable); if (EnableDisable == 0) { DeactivateCollisions(); diff --git a/UnrealFolder/ProjectMobius/Source/ProjectMobius/Public/Controller/MobiusController.h b/UnrealFolder/ProjectMobius/Source/ProjectMobius/Public/Controller/MobiusController.h index 96be032f8..7935180ba 100644 --- a/UnrealFolder/ProjectMobius/Source/ProjectMobius/Public/Controller/MobiusController.h +++ b/UnrealFolder/ProjectMobius/Source/ProjectMobius/Public/Controller/MobiusController.h @@ -96,6 +96,16 @@ class PROJECTMOBIUS_API AMobiusController : public APlayerController UFUNCTION(BlueprintCallable, Category = "MobiusController|Methods|CameraSave") void CycleCameraSavePoints(); + /** Console fallback for the red select-mode button: fires the ActivateCollisions signal. */ + UFUNCTION(Exec) void MobiusActivateCollisions(); + /** Toggle the native left-click agent selection (on by default). */ + UFUNCTION(Exec) void MobiusToggleClickSelect(); + +private: + /** Route plain LMB clicks into the C++ selection trace; the BP click path is unreliable */ + bool bClickSelectsAgent = true; + +public: #pragma region PROPERTIES /** Ptr to the Time dialation subsystem to get the current simulation time */ UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "MobiusController|Properties")