Which is better for my inventory needs? Data Asset or Custom U Obj?

Every item has a pure data form, but wondering if this pure Pure Data form should be in a data asset or custom U object?

I am not considering struct as I don’t like how it replicates everything instead of specific variables.

Also reason asking as some people say data assets are not good as they are not really design to be Mutability at runtime? But I see in the primary data asset you can have individual variables replicated, and in the event graph you can Set their variable and not only just use Get. So data assets seems mutable?

Requirements:

  • can hold lots of variables

  • can make inheritance and expand upon it (thus scalable)

  • fit nicely into an array of items (inventory) while each pure data holder can be of different classes (though from the same parent)

  • can choose specifically which variables to replicate

  • can make presets with different values added

  • can edit the replicated variables at run time and update for all clients (so Mutability at runtime). For ex. like a gun item and I update a variable of how much ammo it has left.

  • when client joins mid way, all the variables will be updated for them

  • good performance even if there are couples thousands or even tens of thousands of these items in pure data form

The first replication is the entire struct (all members), so you have every default the server has. Follow up replication only sends the dirty values.

e.g. If you have a struct with 10 members and only the 5th is changed, then only the 5th is sent.


I use structs and data tables.
Each dynamic item has a parent type class.
For example “Guns” have 7 base types. AR, SR, DMR, SMG, LMG, Pistol, Shotgun

  • Weapon → AR
  • Weapon → DMR
  • Weapon → SR
  • etc

Inventory Reference type Could be Weapon. I prefer Actor.
I use an Interface to handle events and pull data. No casting needed.

Gameplay Tags (GPT) would define the type and specific classification…
Weapon.AR.AK47, Weapon.SR.M24

Using the GPT I do data table lookups to configure the spawned weapon. Set mesh, recoil, ballistics, FX etc etc etc.

Data Tables can be runtime modified. This allows for real time adjustments to specs etc without the need to modify a hard file (data asset, preset etc). You also don’t need a client patch for tweaks to the DT data.

This setup allows me to dynamically create specific weapons from a single parent class.
For an M416 I’d spawn and AR class and configure.

2 Likes

I am also looking for inheritance, an issue with structs is that I need to make a universal item that emcompass furniture, food, and guns, and each of these have variables that the other will never use thus wasting memory. This is why still hesitant on structs.

Why though? You can have a base Item class that offers an identifier (Gameplay Tag), then you create a Base for each Category. Furniture, Food, Weapons etc. You can even do sub types for each category if needed. Each of those can have unique structs.

Anything that’s constant across all classes goes in the root parent. Each Category extends. Each sub category extends further.

This isn’t even a complex system. The vast majority of item while in inventory will be a simple Int for quantity. Only inventory items that are owned and currently spawned should have complexity.


For clarity

WorldItem (Actor)

  • Furniture (WorldItem)
    • Seating (Furniture)
    • Tables (Furniture)
1 Like

I guess I should give more context, I’m trying to have a couple thousand of unique items in the world and the best solution I came up with is to have that item in a pure data form and store it in an array while the actor representation of that item despawns spawns or use obj pool based around the local player’s radius.
For example, so if a player leaves the itemit’s location and data is stored, or when you pick up the items it destroys the actor but copies the datainto your inv.
Also this is multiplayer.
Some items like bulelts can be stack but vast majority of items I want to be unique instances.

I have the player radius system working on multiplayer. I am currently just trying to figure out which pure data form method is better for what I’m doing, either struct or custom u obj.

Except in blueprint inventories are arrays and it will copy the entire array.In C++ you can use FastArrays but then it will copy the entire struct but only at dirty indexes.

they are mutable BUT you’re effectively changing the class default not the instance.

It does sound like you need UObjects, you can make them (Instanced) or use Inheritance. But UObjects are complicated, you need to replicate them manually and handle the lifecycle.

other options are

  1. Combo, have the base data in a DataAsset and the mutable data in a Struct/Object
  2. Just use actors but create a ‘SavedInstance’ when it is stored (ie Inventory)
  3. look into FInstancedStructs for modular data

Thanks will check out those 3 options.

Also, can you go into more detail into this “But UObjects are complicated, you need to replicate them manually and handle the lifecycle.”
How would you manually replciate them, are replicated varialbes good enough?
And how would you handle their life cycle? Are you refering that they always need and ‘outer’ / actor’ to how their ref?

no because UObjects dont replicate at all, you can override this in c++ and add them as a replicatedsubobject to an owning actor

in short yes, otherwise they could get GarbageCollected

My inventory is struct and Actor obj based. If the item is not spawned and attached then it’s a simple int count.

Items in the world are low data. A mesh, interactive collision and an identifier. On pickup the low data variant is destroyed and the high data is spawned and attached either to hand or defined holster slot.