For some reason when I pickup an Item, it has an item in the Inventory array at start. I tried .Empty() and nothing is working. I want the Array to be empty at the beginning of the game but it just starts at 1 and not 0.
void AChad_R_TraceCharacter::Action()
{
if (bCanPickup)
{
tempItem = Item->GetClass();
AddItem();
Item->Pickup();
}
}
void AChad_R_TraceCharacter::OnCollision(class AActor *OtherActor, class UPrimitiveComponent *OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult &SweepResult)
{
AItem *PickedupItem = Cast<AItem>(OtherActor);
if (PickedupItem)
{
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, "I TOUCHED AN ITEM");
Item = PickedupItem;
bCanPickup = true;
}
}
void AChad_R_TraceCharacter::OnExitCollision(class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex)
{
AItem *PickedupItem = Cast<AItem>(OtherActor);
if (PickedupItem)
{
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, "I EXITED AN ITEM");
Item = NULL;
bCanPickup = false;
}
}
void AChad_R_TraceCharacter::AddItem()
{
if (Inventory.Num() > 3)
{
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, "CANNOT GO ANY FARTHER!!!!");
}
else
{
Inventory.Add(tempItem);
getInventory();
}
}
void AChad_R_TraceCharacter::getInventory()
{
int32 count = 0;
for (int32 i = 0; i <= Inventory.Num(); i++)
{
FString InvName = tempItem->GetName();
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, InvName);
count++;
}
FString Counter = FString::FromInt(count);
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Black, Counter);
}