My Array is has an object in it at start?

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);
}

If you’re referring to ::getInventory(), then the bug is in the for loop. The <= should be <. If Inventory.Num() is zero, then count++ will run. However if you switch it to < then when Inventory is zero it won’t run count++.

Thanks for finding this smilingrob! Just a bad operator error on my end :frowning: