Begin overlap not working but end overlap is!?

Working on a simple inventory system where the player picks up items as they collide with them.

For the life of me I can’t get my OnComponentBeginOverlap delegate to be called. But my OnComponentEndOverlap delegate does get called. Does this make any sense?

Both the character and the item itself are set to bGenerateOverlapEvents = true.

relevant Item.h:

UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Item)
UShapeComponent *CollisionShape;


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

UFUNCTION()
	void EndCollision(UPrimitiveComponent* OverlappedComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex);

relevant Item.cpp:
(In constructor)

CollisionShape = CreateDefaultSubobject<UBoxComponent>(TEXT("CollisionShape"));
CollisionShape->bGenerateOverlapEvents = true;
RootComponent = CollisionShape;
	
CollisionShape->OnComponentBeginOverlap.AddDynamic(this, &AItem::BeginCollision);
CollisionShape->OnComponentEndOverlap.AddDynamic(this, &AItem::EndCollision);

Delegate functions:

void AItem::BeginCollision(UPrimitiveComponent* OverlappedComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult)
{
		UE_LOG(LogTemp, Warning, TEXT("player collided with item"));
		GEngine->AddOnScreenDebugMessage(1, 5.f, FColor::Green, FString("PlayerCollided with item"));
		Destroy();
	
}

void AItem::EndCollision(UPrimitiveComponent * OverlappedComp, AActor * OtherActor, UPrimitiveComponent * OtherComp, int32 OtherBodyIndex)
{
	UE_LOG(LogTemp, Warning, TEXT("collision ended"));
	GEngine->AddOnScreenDebugMessage(1, 5.f, FColor::Green, FString("collision ended"));
}

Does it call OnComponentBeginOverlap after it calls OnComponentEndOverlap? OnComponentBeginOverlap will not get called if the component is already overlapping when it spawns.

Begin overlap never gets called. I’ll walk my character into the object and begin overlap does not get called. But when I walk the character out, end overlap is called. I assume this means that my collision rules are working as intended. But I can’t for the life of me figure out why begin overlap isn’t being called.

Hmm. That isn’t compiling. It looks like it wants the UPrimitiveComponent after the AActor.
How do you know the parameters changed? The documentation I’m using is here: OnComponentBeginOverlap | Unreal Engine Documentation

Here’s the compile error after making your change:

error C2664: ‘void TBaseDynamicMulticastDelegate::__Internal_AddDynamic(UserClass ,void (__cdecl AMayhemItem:: )(UPrimitiveComponent *,AActor *,UPrimitiveComponent ,int32,bool,const FHitResult &),FName)’: cannot convert argument 2 from 'void (__cdecl AMayhemItem:: )(UPrimitiveComponent *,AActor ,int32,bool,const FHitResult &)’ to 'void (__cdecl AMayhemItem:: )(UPrimitiveComponent *,AActor *,UPrimitiveComponent *,int32,bool,const FHitResult &)’

Thanks for the help.

Parameters changed in 4.12. Can you try removing “OtherComp” from your BeginCollision and EndCollision? so for example,

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

That’s how I have it and it works for me.

I figured it out, kind of. I renamed my delegates and deleted and recreated the blueprint class that extends my item class and it now works. Not sure which step fixed it.