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"

OnComponentBeginOverlap work for one character but fires multiple time for other

I am using the OnComponentBeginOverlap to detect if the punches of my character are hitting other. I used this code for the player character for the function called by OnComponentBeginOverlap:

 void AMyProjectCharacter::Damage(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult &SweepResult)
     AAI_Character * Enemy = Cast<AAI_Character>(OtherActor);
     if (Enemy)
         if(OtherComp == Enemy->GetCapsuleComponent())
             UE_LOG(LogClass, Log, TEXT("Player punched"));

It is working fine, the Player punch is logged only when the punch hits the enemy and after 5 punches the enemy is destroyed as my enemy health is 50. However i used the same for my enemy character:

 void AAI_Character::Damage(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult &SweepResult)
     AMyProjectCharacter * MyCharacter = Cast<AMyProjectCharacter>(OtherActor);
     if (MyCharacter)
         if (OtherComp == MyCharacter->GetCapsuleComponent())
             UE_LOG(LogClass, Log, TEXT("Enemy punched"));

But with each punch of the enemy, the function gets called many times(3-5 times). I dont get why is it happening. Both the capsule components are identical, For both, OnComponentBeginOverlap is called inside BeginPlay but still this is happenening. The OnComponentBeginOverlap are as follows:

 void AMyProjectCharacter::BeginPlay()
     LeftCollision->OnComponentBeginOverlap.AddDynamic(this, &AMyProjectCharacter::Damage);
     RightCollision->OnComponentBeginOverlap.AddDynamic(this, &AMyProjectCharacter::Damage);


 void AAI_Character::BeginPlay()
     LeftCollision->OnComponentBeginOverlap.AddDynamic(this, &AAI_Character::Damage);
     RightCollision->OnComponentBeginOverlap.AddDynamic(this, &AAI_Character::Damage);

can anyone please help me with my problem. I am new to ue and I found that the answerhub is quit unresponsive to questions. so please someone help me with this.

Product Version: UE 4.19
more ▼

asked Jul 07 '18 at 04:56 AM in C++ Programming

avatar image

1 1 2

(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