Using Data Tables, Structs and Data Assets for an Inventory

Cheers,

To be honest, I think your is the best approach there is. Yes, the whole data table is loaded first time it is accessed but I see this as a perk, not a problem. You can have the names and icons of all items readily available throughout your game. The table itself should be manageable even if you have thousands of entries. (unless the structs are truly gigantic)

That being said there are several things you can do to optimize that.

  1. Make sure your structs are light and with fixed size.
  2. Store copies of those lightweight structs both in the inventory and in the pickup (instead of just the id) This will minimize DataTable look-ups and traversal. (although finding an item by id in a sorted array is lightning fast)

Soft references are useful to hold data that does not conform to the “light-fixed size” struct. You should keep the easy and useful parts of your items in the DataTable and large and unique parts (meshes, animations, 4k textures) as soft reference to load only when needed (lets say when equipped).

Data Assets are useful in the following scenarios:

  • You work with a large team and everyone working in a single DataTable is just not manageable.
  • You have smaller number of large objects.
  • You want to control how the assets are packaged.
  • You want to stream your data because it is too large.

P.S.
I forgot to mention that this is not a clear cut case and there is a lot of opinion involved. You can read all day about DataTable vs DataAssets but, in the end of the day, you can use both of them with very similar effect.

1 Like