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"

Begin/End Overlap same time.

I have a USphereComponent for an enemy character. When the player walks into the sphere, I want it to trigger the enemy to start attacking, etc.

The problem I'm having is when my character walks into the sphere, the OnComponentBeginOverlap is called immediately followed by OnComponentEndOverlap

I setup the collision to only be on pawn, and put special code it to see if the overlap is with the character. It still calls both.

My code looks like this

In enemy character constructor

 mActorRadiusTrigger->OnComponentBeginOverlap.AddDynamic(this, &AEnemyCharacter::TriggerEnter);
 mActorRadiusTrigger->OnComponentEndOverlap.AddDynamic(this, &AEnemyCharacter::TriggerExit);


My trigger functions.

 void AEnemyCharacter::TriggerEnter(AActor* Other, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult)
 {
     if (Other == this)
         return;

     AMyCharacter *character = Cast<AMyCharacter>(Other);
     if (character)
     {
         StartTracking();
     }
 }

 void AEnemyCharacter::TriggerExit(class AActor* Other, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex)
 {
     if (Other == this)
         return;

     AMyCharacter *character = Cast<AMyCharacter>(Other);
     if (character)
     {
         StopTracking();
     }
 }

When I step into the sphere it calls StartTracking() then StopTracking() in the same frame.

If I then back up, it calls StopTracking() a second time.

StartTracking() and StopTracking() currently do nothing, so it's not like the enemy starts moving and moves out of range or something like that.

Product Version: Not Selected
Tags:
more ▼

asked Feb 22 '15 at 08:38 AM in C++ Programming

avatar image

Slayer9292
36 3 4 9

avatar image ThisGuy5234 Mar 01 '15 at 02:36 PM

Do you have physic substepping enabled and moving the actor very fast ?

Is collision for the object activated ?

If you have both collison response and overlap events activated, perhaps you get both start- and endoverlap, because the collision response immediately forces the shapes to be collision-free.

Just ideas...

(comments are locked)
10|2000 characters needed characters left

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