UObject replication problem in non player actor

Hello!

I have an actor for chestbox - ABChestbox. It includes actorComponent UInventory* inventory. UInventory have TArray (UInventoryItem) items; UInventoryItem = child of UObject
All replication rules are checked, for this setup.

ABChestbox:

  • ABChestbox has bReplicated = true

  • ABChestbox → UInventory has UPROPERTY(Replicated)

  • ABChestBox has GetLifetimeReplicatedProps, with DOREPLIFETIME(ABChestBox, inventory);

  • ABChestBox has ReplicateSubobjects with

    • bool repl = Super::ReplicateSubobjects(Channel, Bunch, RepFlags);
    • repl |= Channel->ReplicateSubobject(inventory, *Bunch, *RepFlags);

UInventory:

  • In UInventory TArray items has GetLifetimeReplicatedProps + UPROPERTY(Replicated)

  • Also UInventory has ReplicateSubobject, with replication for each UInventoryItem

    • repl |= Channel->ReplicateSubobject(item, *Bunch, *RepFlags);

UInventoryItem:

  • UInventoryItem has IsSupportedForNetworking() const override { return true; }

  • UInventoryItem created like this - NewObject (UInventoryItem) (GetOwner(), …) - so outer is good and always = ABChestbox (in this case)

  • UInventoryItem has GetLifetimeReplicatedProps with internal data + UPROPERTY(Replicated) for this data

I think i dont forgot something. So in this case if i try to get ABChestBox→UInventory →items. I see items not empty, but all slots are nullptr.

What im missing?

did you GetOwner()→AddReplicatedSubObject();

No, i dont use this technology (Iris Replication System)

ABChestBox has ReplicateSubobjects with inventory

It shouldn’t need to be implemented, because Inventory is an actor component and AActor already implements that for components.


UInventoryItem should also override GetWorld function to get proper world from it’s parent:


if (const UObject* MyOuter = GetOuter())
{
  return MyOuter->GetWorld();
}

Make sure InventoryItem is created by the server

I might be missing something, but in the past I’ve referenced this site to do similar thing and it worked fine, see and check if you have everything needed - it has things like GetFunctionCallspace and CallRemoteFunction, but these are for calling RPCs on your object and replication itself should work fine without them I guess, but you can try and implement everything.

1 Like