I wrote a basic function which should add an Item to an array if the player overlaps the trigger box. Now when i enter the trigger Box, the actor just stops to rotate instead to disappear.
void AItemPickup::Show(bool visible)
{
ECollisionEnabled::Type collision = visible ?
ECollisionEnabled::QueryAndPhysics :
ECollisionEnabled::NoCollision;
this->ItemMesh->SetVisibility(visible);
this->BoxCollider->SetCollisionEnabled(collision);
this->SetActorTickEnabled(visible);
}
void AItemPickup::OnInteract()
{
//FString pickup = FString::Printf(TEXT("Picked up: %s"), *GetName());
//GEngine->AddOnScreenDebugMessage(1, 5.0f, FColor::Red, pickup);
ASpaceGameCharacter* player = Cast<ASpaceGameCharacter>(UGameplayStatics::GetPlayerCharacter(this, 0));
if (player)
{
Show(false);
player->AddToInventory(this);
}
}
void AItemPickup::OnOverlapBegin(UPrimitiveComponent* OverlappedComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult)
{
if ((OtherActor != nullptr) && (OtherActor != this) && (OtherComp != nullptr))
{
OnInteract();
}
}