My UObject doesn’t replicate when I change it’s UPROPERTY variables. For example, if I change the variable StackAmount, it won’t replicate.
Though whenever I add another UObject etc to the array my UObjects are stored in, it gets replicated.
Any ideas as to how I could fix this?
EDIT: It should be noted that I have a struct containing the array of UObjects, and it is the struct I’m replicating.
I know they’re not replicated by default, but I implemented the necessary things to make it replicated.
The thing is, it only replicates when I change the array of UObjects, and not when I change any variable of any of the UObjects.
EDIT: Maybe I should’ve mentioned that I’m not actually using UObject, rather I’m inheriting from it, and using my own class.
Did you also override the ReplicateSubobjects function? Because setting the UPROPERTY to replicated and overriding the functions on the UObject class alone won’t do it.
Yes. This is what it looks like. It’s a 2D inventory system, which is inside a struct called Inventory.
Please note that it works when just adding/removing from the inventory, but changing its variables does not.
Did you also setup all properties as replicated, override the GetLifetimeReplicated props function and called DOREPLIFETIME for all props? Sorry if that sounds like a silly question but you know very often it’s the obvious things that cause issues like this
I think it’s likely that it’s working but your expectations are wrong. When you say it’s not working, I assume you mean that when you change a property inside the object, the OnRep function for the array property is not called? That’s just how array replication works I think, certainly how it used to work. It’s possible they changed it to trigger for value changes in arrays, but even if so it can’t really work like that for pointed-to UObjects due to the extra level of indirection.
When you have a replicating subobject, the instance itself is replicated as part of its owner. This is distinct from properties holding pointers to an object being replicated, which just means that the client gets updates to the pointer if the server makes it point to another object. To respond to replication of changed properties inside a subobject, you’ll need to implement an OnRep for those properties within the subobject class, and perhaps fire a delegate or something so that the class responsible for those objects can process it.
I thought I might have to implement something on my own. I just wanted to see if anybody had an “easy” solution.
Thanks for your answer though, I appreciate it.