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"

OnComponentHit does not work

As in title, my code is: In construcor

.h ////////////////////////////////////////////////////

ASafeLineClickEvent();

UFUNCTION() virtual void OnHit(UPrimitiveComponent HitComponent, AActor OtherActor, UPrimitiveComponent * OtherComponent, FVector NormalImpulse, const FHitResult & Hit);

.cpp ///////////////////////////////////////////////

ASafeLineClickEvent::ASafeLineClickEvent()

{

PrimaryActorTick.bCanEverTick = true; CBoxCom = CreateDefaultSubobject(TEXT("CboxCom")); CBoxCom->SetCollisionEnabled(ECollisionEnabled::QueryOnly); CBoxCom->bGenerateOverlapEvents = true; FScriptDelegate Delegate; Delegate.BindUFunction(this, "OnHit"); CBoxCom->OnComponentHit.AddUnique(Delegate); CBoxCom->SetRelativeLocation(FVector::ZeroVector); CBoxCom->SetNotifyRigidBodyCollision(true);

 RootComponent = CBoxCom;

}

void ASafeLineClickEvent::OnHit(UPrimitiveComponent HitComponent, AActor OtherActor, UPrimitiveComponent * OtherComponent, FVector NormalImpulse, const FHitResult & Hit)

{

 GEngine->AddOnScreenDebugMessage(1, -5.f, FColor::Yellow, TEXT("Hit!"));
 UE_LOG(LogTemp, Warning, TEXT("I'm hit, I'm hit"));
 if (OtherActor && (OtherActor != this))
 {
     GEngine->AddOnScreenDebugMessage(1, -5.f, FColor::Yellow, TEXT("Hit!"));
 }

}

And object collision preset settings

alt text

And other collision settings to interact with

alt text

Product Version: UE 4.16
Tags:
캡처.png (35.3 kB)
캡처h.png (35.6 kB)
more ▼

asked Jun 08 '17 at 03:25 AM in C++ Programming

avatar image

lo1023
1 2 3

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

1 answer: sort voted first

Try this instead:

.h File:

 UFUNCTION()
 void OnHit(UPrimitiveComponent* HitComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, FVector NormalImpulse, const FHitResult& Hit);


.cpp File:

 CBoxCom->OnComponentHit.AddDynamic(this, &ASafeLineClickEvent::OnHit);

The issue is likely occuring because your OnHit() function parameters are wrong, and so the function signature doesn't match.

more ▼

answered Jun 08 '17 at 04:56 AM

avatar image

Reuben Ward
343 8 4 16

avatar image lo1023 Jun 08 '17 at 08:57 AM

Thanks, but it does not work as you say.

If there are several overlapping collisions in the place where Hit happens, is it not Hit?

(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