I followed this tutorial:UE4 c++ OnComponentOverlap and OnComponentHit syntax - YouTube
And used this to create a sphere that triggers hits and overlap events in my scene, this works perfectly. I then tried to apply the same principal and attach the sphere to a vive UMotionController component, where the OnComponentBeginOverlap works but OnComponentHit will not.
VR_Pawn.h:
// Motion Controllers
UPROPERTY(EditDefaultsOnly, Category = "Components")
UMotionControllerComponent* LeftHandComponent;
UPROPERTY(EditDefaultsOnly, Category = "Components")
UMotionControllerComponent* RightHandComponent;
UPROPERTY(EditAnywhere)
USphereComponent* ControllerCollision;
UFUNCTION()
void OnControllerHit(UPrimitiveComponent* HitComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, FVector NormalImpulse, const FHitResult& Hit);
UFUNCTION()
void OnControllerOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult);
VR_Pawn.cpp
void AVR_Pawn::OnControllerOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult){
UE_LOG(LogTemp, Warning, TEXT("CONTROLLER OVERLAP!"));
}
void AVR_Pawn::OnControllerHit(UPrimitiveComponent* HitComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, FVector NormalImpulse, const FHitResult& Hit) {
UE_LOG(LogTemp, Warning, TEXT("CONTROLLER HIT!!"));
}
AVR_Pawn::AVR_Pawn(const FObjectInitializer& objectInitalizer)
:Super(objectInitalizer)
{
PrimaryActorTick.bCanEverTick = true;
BaseEyeHeight = 0.f;
DefaultSceneRoot = CreateDefaultSubobject<USceneComponent>(TEXT("DefaultSceneRoot"));
DefaultSceneRoot->SetupAttachment(RootComponent);
Camera = CreateDefaultSubobject<UCameraComponent>(TEXT("Camera"));
Camera->SetupAttachment(DefaultSceneRoot);
SetActorEnableCollision(true);
LeftHandComponent = CreateDefaultSubobject<UMotionControllerComponent>(TEXT("LeftHand"));
LeftHandComponent->Hand = EControllerHand::Left;
LeftHandComponent->SetupAttachment(DefaultSceneRoot);
ControllerCollision = CreateDefaultSubobject<USphereComponent>(TEXT("RootCollision"));
ControllerCollision->SetupAttachment(LeftHandComponent);
ControllerCollision->SetSphereRadius(20.f);
ControllerCollision->SetHiddenInGame(false);
// ** WORKS **
ControllerCollision->OnComponentBeginOverlap.AddDynamic(this, &AVR_Pawn::OnControllerOverlap);
// ** DOESN'T WORK**
ControllerCollision->OnComponentHit.AddDynamic(this, &AVR_Pawn::OnControllerHit);
}
The LeftHandComponent & ControllerCollision are set to BlockAll with simulation generates hit events ticked.
I left the other sphere I created in the tutorial in the scene, and its hit function fires when the controller enters it, but the controllers hit does not fire.