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"

On Component Begin Overlap

Hey, I have some trouble understanding why Begin Overlap is not working when I want to change the Function name. This is my Code: headerfile:

     UFUNCTION(BlueprintCallable)
             void BeginOverlap(UPrimitiveComponent* OverlappedComponent,
                 AActor* OtherActor,
                 UPrimitiveComponent* OtherComp,
                 int32 OtherBodyIndex,
                 bool bFromSweep,
                 const FHitResult &SweepResult);
         UFUNCTION(BlueprintCallable)
             void EndOverlap(UPrimitiveComponent* OverlappedComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex);


.cpp Constructor:

 PressurePlate->OnComponentBeginOverlap.AddDynamic(this, &APressurePlateBP::BeginOverlap);
     PressurePlate->OnComponentEndOverlap.AddDynamic(this, &APressurePlateBP::EndOverlap);

Functions:

  void APressurePlateBP::BeginOverlap(UPrimitiveComponent * OverlappedComponent, AActor * OtherActor, UPrimitiveComponent * OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult & SweepResult)
     {
         AUsableObject* RequiredActor;
         RequiredActor = Cast<AUsableObject>(OtherActor);
         UE_LOG(LogTemp, Warning, TEXT("Before Required Actor Check"))
         if (RequiredActor)
         {
             //...
         }
         else {
             UE_LOG(LogTemp, Warning, TEXT("Required Actor cast failed"))
         }
     }
     
     void APressurePlateBP::EndOverlap(UPrimitiveComponent * OverlappedComp, AActor * OtherActor, UPrimitiveComponent * OtherComp, int32 OtherBodyIndex)
     {
         AUsableObject* RequiredActor;
         RequiredActor = Cast<AUsableObject>(OtherActor);
         UE_LOG(LogTemp, Warning, TEXT("Before Required Actor Check"))
     
         if (RequiredActor)
         {
             //...
         }
         else {
             UE_LOG(LogTemp, Warning, TEXT("Required Actor cast failed"))
         }
     }

This Code is working fine. But I wanted to add another OnComponentBeginOverlap, so I renamed the functions into :

 void PPBeginOverlap(UPrimitiveComponent* OverlappedComponent,
             AActor* OtherActor,
             UPrimitiveComponent* OtherComp,
             int32 OtherBodyIndex,
             bool bFromSweep,
             const FHitResult &SweepResult);
     UFUNCTION(BlueprintCallable)
         void PPEndOverlap(UPrimitiveComponent* OverlappedComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex);



In the Header and everywhere in .cpp it needs to be changed.. But When I do this, the Box is not triggering anymore. Is "BeginOverlap" an existing Function within the engine? Or why is this not working?

EDIT: So after many tries I figured out, my problem gets solved when I call "OnComponentBeginOverlap" in BeginPlay, instead of the constructor. But this is really weird.. I still do not understand why it do not work anymore, when I rename the function in the constructor? First I thought it could be, that it is saved somewhere in the memory but I restarted my PC a few times. I closed UE4 and "Generated visual Studio files" there is no difference. Every time when I renamed my function "BeginOverlap" it works again.

Product Version: UE 4.21
Tags:
more ▼

asked Nov 30 '18 at 10:50 PM in C++ Programming

avatar image

AnGaraa
10 4 6

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

1 answer: sort voted first

try this:

your header file:

 #pragma once
 
 #include "Engine/TriggerVolume.h"
 #include "YourTriggerName.generated.h"
 
 UCLASS()
 class UNREALCPP_API AYourTriggerName : public ATriggerVolume {
 
     GENERATED_BODY()
     
 protected:
     virtual void BeginPlay() override;
 
 public:
     AMyTriggerVolume();
     UFUNCTION()
     void OnOverlapBegin(class AActor* OverlappedActor, class AActor* OtherActor);
     UFUNCTION()
     void OnOverlapEnd(class AActor* OverlappedActor, class AActor* OtherActor);
 
 };

your cpp file:

 #include "YourTirggerName.h"
 #include "DrawDebugHelpers.h" //can remove it
 
 AYourTirggerName::AMyTriggerVolume() {
 
     OnActorBeginOverlap.AddDynamic(this, &AYourTirggerName::OnOverlapBegin);
     OnActorEndOverlap.AddDynamic(this, &AYourTirggerName::OnOverlapEnd);
 
 }
 
 void AYourTirggerName::BeginPlay() {
 
     Super::BeginPlay();
 
  //(can remove it)   DrawDebugBox(GetWorld(), GetActorLocation(), GetComponentsBoundingBox().GetExtent(), FColor::Purple, true, 999, 0, 5);
 
 }
 
 void AYourTirggerName::OnOverlapBegin(class AActor* OverlappedActor, class AActor* OtherActor) {
 
     if (OtherActor && OtherActor != this) 
     {
         if (GEngine) 
         { 
             GEngine->AddOnScreenDebugMessage(-1, 1.5, FColor::Green, TEXT("Overlap Begin")); //can remove it
             GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Magenta, FString::Printf(TEXT("Overlapped Actor = %s"), *OverlappedActor->GetName())); //can remove it
         }
     }
 }
 
 void AMYourTriggerName:OnOverlapEnd(class AActor* OverlappedActor, class AActor* OtherActor)
 {
     if (OtherActor && OtherActor != this) 
     {
         if (GEngine) 
         {
             GEngine->AddOnScreenDebugMessage(-1, 1.5, FColor::Green, TEXT("Overlap Ended")); //can remove it
             GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Magenta, FString::Printf(TEXT("%s has left the Trigger Volume"), *OtherActor->GetName())); //can remove it
         }
     }
 }

more ▼

answered Dec 01 '18 at 02:30 AM

avatar image

Sejja
37 1 2 6

avatar image NoCodeBugsFree Dec 01 '18 at 06:28 AM

"EDIT: So after many tries I figured out, my problem gets solved when I call "OnComponentBeginOverlap" in BeginPlay, instead of the constructor. But this is really weird.. I still do not understand why it do not work anymore, when I rename the function in the constructor? First I thought it could be, that it is saved somewhere in the memory but I restarted my PC a few times. I closed UE4 and "Generated visual Studio files" there is no difference. Every time when I renamed my function "BeginOverlap" it works again."

This I call hot reload bug. In all my same situations i simply re-parent the BP class to AActor and back and this bug gone. But sometimes even reparenting doesn't help me. Closing the editor and rebuilding with new BP created parent of buggy class completely obliterate this bug for me. P.S. After compiling look at your BP changes in BP class. Sometimes its does't happens for me. Constructor delegates bindings works just fine. No need to place in in begin play.

avatar image AnGaraa Dec 02 '18 at 01:06 AM

I already tested, deleting BP and and make new Child of the C++ class and it did not work. But now when I put it in Begin Play and got it work once, I was able to put it back in Constructor and it is working like it should.

@Sejja I started with creating a seperate class for the trigger first , but then I deleted it, because I find my way is way easier to handle.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
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