Overlap event fires only on new Blueprints

There seems to be an issue when you create a blueprint BEFORE implementing a OnComponentBeginOverlap event on a component.
The issue is known since at least two years ago: OnComponentBeginOverlap not working - World Creation - Unreal Engine Forums

The OP set the issue as solved by finding a workaround, but I don’t feel it’s really solved.

So with my class, when I use my existing Blueprints derived from it, nothing happens.
But when I create a new Blueprint derived from my class, the event fires as expected.

InventoryItem.h:

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

InventoryItem.cpp:

PickupRadius = CreateDefaultSubobject<USphereComponent>(TEXT("PickupRadius"));
	PickupRadius->SetSphereRadius(200);
	PickupRadius->SetCollisionEnabled(ECollisionEnabled::QueryOnly);
	PickupRadius->SetCollisionObjectType(ECollisionChannel::ECC_WorldDynamic);
	PickupRadius->SetCollisionResponseToAllChannels(ECollisionResponse::ECR_Ignore);
	PickupRadius->SetCollisionResponseToChannel(ECollisionChannel::ECC_Pawn, ECollisionResponse::ECR_Overlap);
	PickupRadius->OnComponentBeginOverlap.AddDynamic(this, &AInventoryItem::OnEnterPickupRange);
	PickupRadius->OnComponentEndOverlap.AddDynamic(this, &AInventoryItem::OnLeavePickupRange);

InventoryItem.cpp:

void AInventoryItem::OnEnterPickupRange(UPrimitiveComponent* OverlappedComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult) {
	GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, TEXT("Entered Pickup Range"));
	if (OtherActor == UGameplayStatics::GetPlayerCharacter(GetWorld(), 0)) {
		InPickupRange = true;
	}
}

The solution mentioned is to re-create all your derived Blueprints, which may be acceptable when you only have a few, but not when you have around 20 of them!

Is there any other way to make the existing Blueprints recognize the changes?
I really hope this is just a rare case…

Hey ballerbaer-

I tried testing this using the following setup:

  • Create a new actor class and a blueprint of the class.
  • Add instance of the blueprint to the level
  • Add the following code to the class:

(.h)

UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Test)
 UBoxComponent* MyBox;

UFUNCTION(BlueprintCallable, Category = test)
void OverlapFunction(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult & SweepResult);

(.cpp - the first two lines are inside the constructor)

MyBox= CreateDefaultSubobject<UBoxComponent>(TEXT("MyBox"));
	MyBox->OnComponentBeginOverlap.AddDynamic(this, &AMyActor::OverlapFunction);

     void AMyActor::OverlapFunction(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult & SweepResult)
{
	if (GEngine)
	{
		GEngine->AddOnScreenDebugMessage(-1, 4.f, FColor::Magenta, TEXT("Overlap Triggered"));
	}
}

After compiling the code I was able to PIE with the blueprint instance that was already created which printed my message as expected. Can you verify if this setup prints the message for you or if you are using a different setup method that is causing the behavior you’re seeing?

Hey Doug,

you’re right, I can’t reproduce it now either. I tried it with the exact same setup I used before.

I don’t know what causes this, but I had to recreate all derived Blueprints for it to work properly, without changing any code. Strange.

Thanks anyway.

I had the issue again and finally tracked it down.
Turned out to be a bit different then I first thought.

I didn’t try it on a clean project yet, but it should work:

  1. Create the actor .cpp/.h as above
  2. Create a Blueprint of the class
  3. Add as instance to the level and try it out (event should fire)
  4. Now rename “OverlapFunction” to something else
  5. Build and try (event should NOT fire)

When you rename it back to “OverlapFunction” afterwards, it will start to work again, so there has to be something cached and not get refreshed correctly.
This can be very confusing when you just started and rename things often.

I also tried

  • re-generating the project files
  • removing the event → rebuild → test → re-add the event → rebuild
  • duplicate the blueprint

nothing works but re-creating the blueprints from scratch (or just rename the function back)

The issue of renaming a function that is bound to a delegate is a known issue that is reported here: Unreal Engine Issues and Bug Tracker (UE-38419) . You can track the report’s status as the issue is reviewed by our development staff. Please be aware that this issue may not be prioritized or fixed soon.