InventoryStruct is a UProperty of the InventoryComponent. Each slot have as Outer the InventoryComponent.
The struct is perfect to organize and initialize all slots (each substruct have an init function). Is there any way to do this UObject replication with the slot ?
Also based on what I found on the web, nobody agrees on the best way to make an inventory replicated… Some people say to make AActor item/slot to replicate them, other say that replicate high number of AActor isn’t a good idea for the network performance… Our game is survival multiplayer (like Ark), there will be potentially a ton of item in their inventory, what way would be optimal to reduce network usage ?
Hello, I’ve tried to use approach you’ve mentioned but I faced a problem. For example I have Component and UObject* member inside:
UTestObject* testObject;
Inside UTestObject I just have a simple field like this:
UPROPERTY(Replicated)
int m_currentAmount = 0;
I also implemented both IsSupportedForNetworking and GetLifetimeReplicatedProps functions.
Then on both Server/Client in begin play I create testObject via NewObject. Then at somepoint of time I made an RPC call and change m_currentAmount on Server and I don’t receive this update on client.
However, if I change pointer itself, for example made something like this:
testObject = nullptr;
I will get an update on Client. Seems like it only replicates pointer by itself, but not the data inside pointer.
Do you know how to fix this? Thanks
structs cant carry subobject channels, so a UObject pointer inside a struct only replicates the pointer, never the object behind it. that is exactly what exelim hit here: setting the pointer to null replicates, changing m_currentAmount inside doesnt, because there is no channel for the object itself.
the fix is to keep the array of slot objects directly on the inventory component, not inside the struct. outer each slot to the component, create them only on the server, mark the class IsSupportedForNetworking, register its vars with DOREPLIFETIME, and replicate each slot through ReplicateSubobjects on the component. keep the struct for layout or config if you like, but the replicated state lives on the objects.
you can also try Blueprint Object Replication, a UObject replication plugin for Unreal Engine that lets a component own blueprint item objects with replicated properties and notifies, so the struct nesting is not needed: https://www.fab.com/listings/e26dcf07-7c78-4e67-8e56-272cf6df8021