I’m trying to set up a drop object that the player can pick up if he enters a trigger component of the drop. This should be fairly easy to manage with only C++ code, the class is created as normal but for some reason I can’t add a dynamic to OnComponentBeginOverlap. Here’s my code:
Header
UCLASS()
class PROJECTWAIFU_API ADrop : public AActor
{
GENERATED_BODY()
public:
// Sets default values for this actor's properties
ADrop();
// Called when the game starts or when spawned
virtual void BeginPlay() override;
// Called every frame
virtual void Tick( float DeltaSeconds ) override;
UPROPERTY(VisibleAnywhere)
USphereComponent* grabBox;
UFUNCTION()
void OnOverlapBegin(UPrimitiveComponent* OverlappedComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult);
};
.cpp
ADrop::ADrop()
{
grabBox = CreateDefaultSubobject<USphereComponent>(TEXT("Grab collision"));
grabBox->SetSphereRadius(200.0f);
grabBox->bGenerateOverlapEvents = true;
grabBox->OnComponentBeginOverlap.AddDynamic(this, &ADrop::OnOverlapBegin);
}
void ADrop::OnOverlapBegin(UPrimitiveComponent* OverlappedComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult)
{
// ...
}
AddDynamic seems to be working but OnOverlapBegin() will never be called. Are there any other properties I may be missing?