Whats the best way to store an inventory inside an inventory?

for instance a backpack inside a crate?

note: it needs to be both replicated and saveable

so i’d like to use a struct because that’s both easy to replicate and save but a struct cant have circular dependancy. (items within items)

so next is an object but thats not replicated by default and also id need to save the contents to a struct anyway which has the above problem.

an actor component replicates but still has the save problem. and also wastes performance

so ive got a few solutions that all feel awkward and since inventories are big investments i’d like some advice first?

Cheers

Is not a

circular dependancy

yet. Providing they use different structs.

inventories are big investments

Preach :palms_up_together:

Strictly for saving, loading, and replication, seems like each “Container” being a UCLASS that has a TArray of Containers, would work? Seems straightforward.

that would work 1 level deep bit if we have a small pouch inside a backpack inside a container you’d need structs for every level, i also have mod slots which are technically items too.

i should also mention each item has custom data like durability so i cant just save a data asset or table row name

The approach mentioned by @Everynone works for an arbitrary number of recursion levels if you simply use the same struct:

If each item has a custom data for durability, it can also have a custom data for the items it stores.
The backpack, crate and bags only have to be items too.
An item only has to be a hashkey that can have all the related tables you need, both static and dynamic.

thats what im leaning towards, basically a guid for each item and the inventory just references the guid, the only annoying thing then is i have to look up the item from its guid in possibly 100s of items everytime i want to access it

Well, it is not something that you have to do every frame, but if you are going to have a lot of data and you are afraid of performance you can use SQL or similar databases, they are very fast with queries, and there are several plugins in the marketplace.