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.

the array replicates, the pointers inside it do not. on the client there is no UInventoryItem instance to point at, so every slot resolves to null, which is exactly what you see.

King_Zero is right that the component does not need its own ReplicateSubobjects override and the GetWorld override on the item matters. what is missing is registration, each item has to go into the replicated subobject list of the actor that owns it, and it has to be created on the server only with a stable outer. a replicated TArray of UObject pointers carries the references, it doesnt create the objects.

if you want to stay in blueprint that registration is exactly the piece you cannot write yourself. blueprint object replication from fab is a UObject replication plugin that hosts the objects on a component, server creates them, clients get them with their rep notifies, ue5.0 to 5.8.

btw i used blueprint object replication from fab https://www.fab.com/listings/e26dcf07-7c78-4e67-8e56-272cf6df8021 it worked for me