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"

Something causing my Begin/EndOvelapEvent handlers to crash UE4

What I'm trying to do:

I have 3 weapons placed near each other in a way that a bit of their sphere components collide with each other so the character might be inside two sphere components at the same time.

When my character gets close to a weapon I show a small widget in the bottom of the screen with an icon representing the weapon and enable my character to pick it up (being picked up is handled by the weapon's code). When my character gets far from the weapon or pick's it up I hide the widget (Picking up the weapon will disable collision on the sphere component of the weapon thus triggering an end overlap event).

Since the character might be inside two spheres at the same time I made it so that only the newest overlapped weapon can get input and have its widget shown and when the end overlap event is triggered for the newest weapon I check currently overlapping actors to see if there's a weapon in there and if there was one I enable its input and show its widget.

I was trying to see if my code works correctly so I just randomly moved my character in between the weapons and it worked like a charm and the widgets were changing correctly but after about a minute it suddenly it crashed. I commented out the content of the CheckOverlappingActors(), which does the stuff in bold in the previous paragraph, to see if the problem was from that function but it still crashed after about a minute. It sometimes crashes way faster so it's happening when a rare condition is met I guess, but I don't know what condition might be causing it. What am I doing wrong?

I put those logs to see when it crashes but every time it crashes either after End2 or after Begin2 so I don't have any clues on what line is causing the crash.

Here's my code:

 void ATPSShooterCharacter::BOverlapHandler(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult & SweepResult)
 {
     AMasterWeapon* OverlappedWeapon = Cast<AMasterWeapon>(OtherActor);
     if (OverlappedWeapon != nullptr) {
         UE_LOG(LogTemp, Warning, TEXT("Begin1"));
         if (CurrentOverlappedWeapon) {
             CurrentOverlappedWeapon->DisableInput(Cast<APlayerController>(GetController()));
             CurrentOverlappedWeapon->POwner = nullptr;
             if (CurrentOverlappedWeapon->WidgetInstance->IsInViewport()) {
                 CurrentOverlappedWeapon->WidgetInstance->RemoveFromViewport();
             }
         }
         OverlappedWeapon->POwner = this;
         OverlappedWeapon->EnableInput(Cast<APlayerController>(GetController()));
         CurrentOverlappedWeapon = OverlappedWeapon;
         if (!OverlappedWeapon->WidgetInstance->IsInViewport()) {
             OverlappedWeapon->WidgetInstance->AddToViewport();
         }
         UE_LOG(LogTemp, Warning, TEXT("Begin2"));
     }
 }
 
 void ATPSShooterCharacter::EOverlapHandler(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex)
 {
     AMasterWeapon* OverlappedWeapon = Cast<AMasterWeapon>(OtherActor);
     if (OverlappedWeapon != nullptr) {
         UE_LOG(LogTemp, Warning, TEXT("End1"));
         OverlappedWeapon->DisableInput(Cast<APlayerController>(GetController()));
         OverlappedWeapon->POwner = nullptr;
         if (CurrentOverlappedWeapon == OverlappedWeapon) {
             if (OverlappedWeapon->WidgetInstance->IsInViewport()) {
                 OverlappedWeapon->WidgetInstance->RemoveFromViewport();
             }
             CurrentOverlappedWeapon = nullptr;
             CheckOverlappingActors();
         }
         UE_LOG(LogTemp, Warning, TEXT("End2"));
     }
 }


EOverlap -> EndOverlap, BOverlap -> BeginOverlap

Product Version: UE 4.21
Tags:
more ▼

asked Mar 22 '19 at 07:29 PM in C++ Programming

avatar image

Afrytex
1 1

(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