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"));
}