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 - Epic Developer Community 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…