Hi,
I have a problem with overlap functions. I’m using FPS template, and I want to display a massage to the player when he wants to pick up a weapon. So, I added OnSphereEndOverlap function (OnSphereBeginOverlap was already there). My problem is that OnSphereBeginOverlap works only once, while OnSphereEndOverlap works every time I move away from the weapon, and I don’t know why.
Edit: I don’t want to fire EndOverlap once, but I want to fire BeginOverlap every time
void UTP_PickUpComponent::BeginPlay()
{
Super::BeginPlay();
// Register our Overlap Event
OnComponentBeginOverlap.AddDynamic(this, &UTP_PickUpComponent::OnSphereBeginOverlap);
OnComponentEndOverlap.AddDynamic(this, &UTP_PickUpComponent::OnSphereEndOverlap);
}
void UTP_PickUpComponent::OnSphereBeginOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult)
{
// Checking if it is a First Person Character overlapping
AFPSOpenWorldCharacter* Character = Cast<AFPSOpenWorldCharacter>(OtherActor);
if(Character != nullptr)
{
Character->bCanShowPickUpUMG = true;
GEngine->AddOnScreenDebugMessage(-1, 5.0f, FColor::Red, TEXT("Begin"));
// Notify that the actor is being picked up
OnPickUp.Broadcast(Character);
// Unregister from the Overlap Event so it is no longer triggered
OnComponentBeginOverlap.RemoveAll(this);
}
}
void UTP_PickUpComponent::OnSphereEndOverlap(UPrimitiveComponent* OverlappedComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex)
{
AFPSOpenWorldCharacter* Character = Cast<AFPSOpenWorldCharacter>(OtherActor);
if (Character != nullptr)
{
Character->bCanClosePickUpUMG = true;
GEngine->AddOnScreenDebugMessage(-1, 5.0f, FColor::Red, TEXT("End"));
}
}