x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

CPP VIVE Controller OnComponentHit doesn't fire

I followed this tutorial:https://www.youtube.com/watch?v=NAbLfvTJLrw

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.

Product Version: UE 4.12
Tags:
more ▼

asked Jun 27 '16 at 11:21 AM in C++ Programming

avatar image

Zaaa
1 1 2

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

Coming back to this. I solved it by removing all the overlap code, closing unreal, regenerating the VS projects files, clean and build and it worked. Something was lingering from the build overlap code but I could not find it.

more ▼

answered Nov 09 '17 at 07:11 PM

avatar image

Zaaa
1 1 2

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question