Hi guys, here’s my setup.
This is done in the spawned PlayerCharacter:
CharacterInventory = CreateDefaultSubobject<UInventoryActorComponent>(TEXT("Inventory"));
CharacterInventory->SetIsReplicated(true);
The “UInventoryActorComponent” is a “UActorComponent” with an array “TArray< FItemData > Inventory”.
When I want to add something to this inventory, I call this from the character:
void AProjectZCharacter::ServerAddPickupItemToInventory_Implementation(AItemPickup* NewItem)
{
if (NewItem)
{
if (GetCharacterInventory()->AddToInventory(NewItem->GetItemData()))
{
if (NewItem->GetIsDestroyedOnPickup())
{
NewItem->Destroy();
}
for (int i = 0; i < GetCharacterInventory()->GetAllInventoryItems().Num(); i++)
{
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Emerald, "Inventory on Server " + CharacterInventory->GetAllInventoryItems()[i].ItemName);
}
}
}
}
My probem is that the changes to the Inventory are never replicated to the Client PlayerCharacter. The Inventory updates on the server, but the Client doesn’t see the changes. Am I missing something?
I also tried setting the variable inside the InventoryComponent to “UPROPERTY(Replicated)” but that doesn’t work either.
Thanks for your time and help!