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"

OnComponentEndOverlap is never fired [UE 4.10]

Hi, I was doing a FP item grab mechanism in C++. When the player overlaps the item it should set a boolean variable (bIsWithinRange) to true, and when it's not overlaping it should set the variable to false. I use this variable as a condition check for the player to be able to pick the item up.

Everything is working fine except OnComponentEndOverlap, which seems to be never firing. Any ideas? Code below...

 AItem::AItem()
 {
      // Set this actor to call Tick() every frame.  You can turn this off to improve performance if you don't need it.
     PrimaryActorTick.bCanEverTick = true;
 
     TBox = CreateDefaultSubobject<UBoxComponent>(TEXT("Box"));
     TBox->bGenerateOverlapEvents = true;
     TBox->OnComponentBeginOverlap.AddDynamic(this, &AItem::TriggerEnter);
     TBox->OnComponentEndOverlap.AddDynamic(this, &AItem::TriggerExit);
 
     RootComponent = TBox;
 
     SM_TBox = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("Box Mesh"));
     SM_TBox->AttachTo(RootComponent);
 
 }


 void AItem::TriggerEnter(class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult &SweepResult) {
     bItemIsWithinRange = true;
     GEngine->AddOnScreenDebugMessage(1, 5.f, FColor::Green, FString::Printf(TEXT("Press E to pickup %s"), *ItemName));
     GetPlayer(OtherActor);
 }
 
 void AItem::TriggerExit(class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex) {
     bItemIsWithinRange = false;
     GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Blue, FString::Printf(TEXT("EndOverlap"))); //To check if this function is called. It's never called.
 }





Product Version: UE 4.10
Tags:
more ▼

asked Apr 23 '16 at 05:39 PM in C++ Programming

avatar image

dechichi01
1 2 2

avatar image PrinfD Apr 23 '16 at 06:35 PM

Did you maybe forget to mark your TriggerExit function as UFUNCTION?

avatar image dechichi01 Apr 23 '16 at 06:43 PM

Thanks PrinfD! Actually I didn't forget, but your answer made me think about trying something I haven't. The declarations were like this:

 UFUNCTION()
         void TriggerEnter(class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult &SweepResult);
         void TriggerExit(class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex);

Looks like this doesn't work, so I tried this:

 UFUNCTION()
         void TriggerEnter(class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult &SweepResult);
 UFUNCTION()
         void TriggerExit(class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex);

Thank you very much!

avatar image PrinfD Apr 23 '16 at 06:56 PM

Always happy to help.

The behavior is actually expected, as the UFUNCTION() makro only marks the next function declaration as UFUNCTION, that's why you have to use it before each of those functions.

avatar image elliotENGi Aug 14 '16 at 02:45 PM

Dayumm - Was scratching my head for an hour trying to work this out, and it was just because I was silly enough to forget the UFUNCTION() macro.
Finally google and answerhub came through haha. Good tip PrinfD lol.

(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