So I am trying to create a functionality to pick up items from the ground using a sphere component. When you overlap the spherecomponent of an item you will be able to interact with it and pick it up
CODE:
void APickableItem::PlayerInteract(AActor* InteractActor)
{
SetActorHiddenInGame(true);
SetActorTickEnabled(false);
SetActorEnableCollision(false);
this->AttachToActor(InteractActor, FAttachmentTransformRules::SnapToTargetIncludingScale, NAME_None);
}
In a realistic game environment, the player can overlap multiple actors at once, and in my case when that happens i pick the closest one.(using function from above); The problem is that if the items are to close to each other, and their spherecomponent intersect, when I call SetActorEnableCollsion(false) it will trigger OnOverlapEnd on all other items while the player is still overlapping them. Is there a way to filter the data types that can trigger OnEndOverlap? My solution for now resides in the comments from the code below
CODE:
void AInteractableActor::BeginPlay()
{
Super::BeginPlay();
if (InteractMessageWidgetComponent)
{
InteractMessageWidgetComponent->SetVisibility(false);
}
if (WidgetVisTrigger)
{
WidgetVisTrigger->OnComponentBeginOverlap.AddDynamic(this, &AInteractableActor::OnOverlapBegin);
WidgetVisTrigger->OnComponentEndOverlap.AddDynamic(this, &AInteractableActor::OnOverlapEnd);
}
}
void AInteractableActor::OnOverlapBegin(UPrimitiveComponent* OverlappedComp, AActor* OtherActor,
UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult)
{
//if (!OtherActor->IsA(AInteractableActor::StaticClass()))
//{
InteractMessageWidgetComponent->SetVisibility(true);
//}
}
void AInteractableActor::OnOverlapEnd(UPrimitiveComponent* OverlappedComp, AActor* OtherActor,
UPrimitiveComponent* OtherComp, int32 OtherBodyIndex)
{
//if (!OtherActor->IsA(AInteractableActor::StaticClass()))
//{
InteractMessageWidgetComponent->SetVisibility(false);
//}
}