So Im trying to replicate my inventory system thats holds item in a TArray of UObjects (item class). I’m trying the new replicated Subobjects thats listed here:
I can get it to work with with single replicated UObject variables. But if I want to make an a TArray such as TArray<UItem*> Items; and modify a property such as the Owner of a single item in that array Items, I can’t figure it out? Does anything have any experience with this? ```
AddReplicatedSubObject(MySubObject) only allows UObjects and not arrays of UObjects. I tried adding each item of my Items array to AddReplicatedSubObject but it doesn’t work.
I’m running into the same issue, did you find any workaround?
It also seems to be like the old ReplicateSubobjects(UActorChannel* Channel, FOutBunch* Bunch, FReplicationFlags* RepFlags) method is no longer being called so the approach that worked for replicating TArrays in UE4 is no longer working. This seems like a pretty big loss in functionality with the new approach to replicating subobjects.
you are right that AddReplicatedSubObject only takes one object, so for an array you loop it. on the server, after you create each item with outer set to the owning actor or component, call AddReplicatedSubObject for every element, and RemoveReplicatedSubObject when an item is destroyed or removed from the inventory. the item class itself needs IsSupportedForNetworking true and its own GetLifetimeReplicatedProps for things like Owner, otherwise the channel exists but carries nothing.
modifying Owner on one element then works because the subobject has its own channel once registered. the wrapper UObject idea from the thread also works but its just manual bookkeeping for the same thing, one extra object whose only job is holding the array.
you can also try Blueprint Object Replication, a UObject replication plugin for Unreal Engine that replicates arrays of item objects from a component with variables and rep notifies handled for you, iris ready: https://www.fab.com/listings/e26dcf07-7c78-4e67-8e56-272cf6df8021