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 triggering multiple times

I am trying to decrease the number of lives a player has when a ball hits an actor marked with the "deadzone" tag but sometimes, when the ball hits the deadzone, 2,3 or 4 lives are removed and I do not know why. Here is my OnHit code:

 void ABall::OnHit(UPrimitiveComponent* HitComponent, AActor* OtherActor, UPrimitiveComponent* OtherComponent, FVector NormalImpulse, const FHitResult& Hit)
     // Other Actor is the actor that triggered the event. Check that is not ourself.  
     if ((OtherActor != nullptr) && (OtherActor != this) && (OtherComponent != nullptr))
         if (OtherActor->ActorHasTag("DeadZone") /*&& !bHasCollided*/)
             //UE_LOG(LogTemp, Warning, TEXT("Dead"));
             bIsLaunched = false;
             //bHasCollided = true; //I can prevent multiple hits with a boolean but would rather understand why it's happening

When I use a breakpoint to debug, I can see that the function is called multiple times, but I really don't know why. Sometimes it works fine, but most of the time, it's triggered on multiple occasions. Any help appreciated.

Product Version: UE 4.21
more ▼

asked Mar 27 '19 at 09:48 PM in C++ Programming

avatar image

1 3 1 5

avatar image JayFitz91 Mar 28 '19 at 09:23 PM

I've also tried this with NotifyHit(class UPrimitiveComponent* MyComp, AActor* Other, class UPrimitiveComponent* OtherComp, bool bSelfMoved, FVector HitLocation, FVector HitNormal, FVector NormalImpulse, const FHitResult& Hit) but I am experiencing the same behaviour so I do not believe the issue lies with OnComponentHit

avatar image emperor_katax Mar 29 '19 at 04:48 AM

Can you please share a git repo for your project? … this looks strange issue..

avatar image Creo May 26 '19 at 12:39 PM

Have the same issue. Looks like it depends on a count of supsteps (Physics Substepping). Tested on 4.22.0

avatar image Lobotomiac May 30 '19 at 01:34 PM

Try SetNotifyRigidBodyCollision(false) inside OnHit to make it not call it again after the 1st time

avatar image Creo May 30 '19 at 01:38 PM

And it will never call again =)

avatar image Lobotomiac May 30 '19 at 01:56 PM

You can use a timer to set it back up, or whatever logic you're using in it.

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

0 answers: sort voted first
Be the first one to answer this question
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