I think you got me on the right track but I am still having problems replicating the inner inventory. Your last paragraph is what I am trying to implement.
In my UItem base class, I created a new function:
bool UItem::ReplicateSubobjects(UActorChannel* Channel, FOutBunch* Bunch, FReplicationFlags* RepFlags)
{
// base class has no subobjects to replicate
return false;
}
In my backpack (UWearableInventoryItem) I override this new function with:
bool UWearableInventoryItem::ReplicateSubobjects(UActorChannel* Channel, FOutBunch* Bunch, FReplicationFlags* RepFlags)
{
bool bWroteSomething = false;
//if (Channel->KeyNeedsToReplicate(Inventory->GetUniqueID(), Inventory->GetReplicatedItemsKey()))
{
bWroteSomething = Channel->ReplicateSubobject(Inventory, *Bunch, *RepFlags);
}
return bWroteSomething;
}
In my UInventoryComponent I called the new function so that subobjects of each UItem could be written to the channel
bool UInventoryComponent::ReplicateSubobjects(UActorChannel* Channel, FOutBunch* Bunch, FReplicationFlags* RepFlags)
{
bool bWroteSomething = Super::ReplicateSubobjects(Channel, Bunch, RepFlags);
if(Channel->KeyNeedsToReplicate(GetUniqueID(), ReplicatedItemsKey))
{
for(auto& Item : Items)
{
// provides an opportunity for Item to replicate subobjects
bWroteSomething |= Item->ReplicateSubobjects(Channel, Bunch, RepFlags);
if(Channel->KeyNeedsToReplicate(Item->GetUniqueID(), Item->RepKey))
{
bWroteSomething |= Channel->ReplicateSubobject(Item, *Bunch, *RepFlags);
}
}
}
return bWroteSomething;
}
So far my UInventoryComponent inside the UItem contains no items after replication. I wanted to respond where I am so far to make sure I understood what you were saying, but I am also trying to simplify my project to make debugging easier. I’ll report back more information once I get a bit further in my testing. Thanks!