Array in Component

Component.h
private:
UPROPERTY(EditAnywhere, Replicated, Category = “Inventory”)
TArray<ASItemActor*> Inventory;

public:
UFUNCTION(BlueprintCallable, Category = “Inventory”)
TArray<ASItemActor*> GetInventory();

Component.cpp
TArray<ASItemActor*> UInventoryContainerComponent::GetInventory()
{
return Inventory;
}

Pickup.cpp
void ASItemPickup::OnUsed(APawn* InstigatorPawn)
{
ASCharacter* MyPawn = Cast<ASCharacter>(InstigatorPawn);
if (MyPawn)
{
FActorSpawnParameters SpawnInfo;
SpawnInfo.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AlwaysSpawn;
ASItemActor* NewItem = GetWorld()->SpawnActor<ASItemActor>(ItemActorClass, SpawnInfo);

            //InventoryContainer is the Component
	MyPawn-&gt;GetInventoryContainer()-&gt;GetInventory().Add(NewItem);

            //InventoryTest is the same Inventory only directly on the Pawn not in a Component
	MyPawn-&gt;InventoryTest.Add(NewItem);

	NewItem-&gt;SetActorLocation(MyPawn-&gt;GetActorLocation());
	NewItem-&gt;SetActorEnableCollision(false);

	GEngine-&gt;AddOnScreenDebugMessage(-1, 15.0f, FColor::Red, "Added to Inventory.");

	Super::OnUsed(InstigatorPawn);
 }

}