> For the complete documentation index, see [llms.txt](https://lifeexe-art.gitbook.io/unreal-engine-c-course-eng/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://lifeexe-art.gitbook.io/unreal-engine-c-course-eng/lessons/lecture-079/ammo-is-not-picked-up-if-character-spends-ammo-at-the-pickup-respawn-point.md).

# Ammo is not picked up if character spends ammo at the pickup respawn point

### Problem

* Get up to the pickup respawn point with full ammo
* Shoot (one shot is enough)
* Pickup can't be taken

### Solution

* Create an array of pointers to `APawn` in the base pickup:

```cpp
UPROPERTY()
TArray<APawn*> OverlappingPawns;
```

* In `NotifyActorBeginOverlap`, if it was not possible to take the pickup, we add the pointer to the pawn to the array:

```cpp
void ASTUBasePickup::NotifyActorBeginOverlap(AActor* OtherActor)
{
    Super::NotifyActorBeginOverlap(OtherActor);

    const auto Pawn = Cast<APawn>(OtherActor);
    if (GivePickupTo(Pawn))
    {
        PickupWasTaken();
    }
    else if (Pawn)
    {
        OverlappingPawns.Add(Pawn);
    }
}
```

* In tick function (you can also make a custom timer), iterate through the array and see if we can give someone a pickup from the saved pointers in the array, and if we can, then we give it to:

```cpp
void ASTUBasePickup::Tick(float DeltaTime)
{
    Super::Tick(DeltaTime);

    AddActorLocalRotation(FRotator(0.0f, RotationYaw, 0.0f));

    for (const auto OverlapPawn : OverlappingPawns)
    {
        if (GivePickupTo(OverlapPawn))
        {
            PickupWasTaken();
            break;
        }
    }
}
```

* Override the `NotifyActorEndOverlap` function (which is called, as you might guess, when the actor exits the collision) and in it we remove the pawn pointer from the array:

```cpp
void ASTUBasePickup::NotifyActorEndOverlap(AActor* OtherActor)
{
    Super::NotifyActorBeginOverlap(OtherActor);

    const auto Pawn = Cast<APawn>(OtherActor);
    OverlappingPawns.Remove(Pawn);
}
```

[Commit in repository](https://github.com/life-exe/UnrealEngine/commit/0da7b42056072fd2bd01d67aaeed26720ceb6e0b)
