The inventory system works perfectly on the server, for both the client and server. However, when a client picks up items, the InventoryContents array gets filled with nulls. Here’s a log of the inventory after picking up 3 items:
Thanks for the suggestion @Auran13. I have tried to change the definition of my ItemBase to inherit from AActor, and it didnt help.
I’ve been tinkering around for a while now and setting bReplicates, or even serializing the object manually or replicating each property of the AItemBase manually did not make any change either.
I have tried to create a copy of TArray<AItemBase *> InventoryContents in the PlayerCharacter and update it each time server updates it’s version from the AInventoryActorComponent, but it has also replicated only nulls.
I did try changing the array declaration to TArray<TObjectPtr>, but no luck.
You need to somehow replicate your items
If they are actors, then they can replicate themselves
If they are objects, they need to be replicated through an actor, like for example the inventory owner
It’s pretty easy if you set bReplicateUsingRegisteredSubObjectList to true on your actor, and then when creating the item to add it to the inventory, you also add it as a replicated subobject using AddReplicatedSubObject(MyItem)
That should then replicate the item to other clients, and the pointers should be valid on clients as well
Thank you @zeaf, This has put a new light on the case. After implementing this form of UObject replication the client started to see the array of empty (not initialized) objects rather than array of nulls - which is a progress.
for the context this is how I initialize the objects before adding to the inventory:
Thank you @zeaf.
Setting bReplicateUsingRegisteredSubObjectList method of replicating UObject worked when also marked all UItemBase properties for replication
I mark your answer as Solution as this mostly solves my problem, but I’d appreciate if you could help me understand why It wouldnt work when replicating array of AActors even if configured as: