Good solution for a complex BP inventory? (and saving it)

So there are a few BP inventory tutorials around, but nothing that really covers what I’m looking for, at least not that I’ve been able to find. Most just cover storing actors and data in their default state, but I’m working on a project that will need a bit more than that, and information is a bit hard to come by.

So for an example of what I’m looking to do:

Each player in a MP game has 50 inventory slots. Each inventory slot can be used for various weapons, resources, and items. Pretty simple so far, until this: Every weapon, resource, etc will have unique stats on them, and what stats the item has will change depending on what the item is.

Looking at a weapon, it can have, so far, 14 properties that would each need to be saved, none of which would be useful in the slightest to any other item type in the game.

Now, I know it’s entirely possible for me to go and make 700 variables for the weapon item type alone, 14 for each of the 50 inventory slots, but even with my limited programming knowledge that sounds like a horrible, horrible idea.

What would be the best approach to storing all of that data without needing to make a massive network of blueprints solely to store data in the inventory slots? Or better yet, a solution that doesn’t have a limit to the amount of inventory slots without a major reworking, so I’m able to go back later and adjust it easily.

At the moment, what I have so far is basically a “master weapon”, “master projectile”, “master resource”, etc that changes its properties after spawning based on the variables that the player gives it from a single slot in the inventory. But, at the moment I only have it functioning with 1 item at a time, just for testing purposes until I work out a good solution, and even as it is having so many variables is getting hectic.

Thanks in advance!

Well, those simple inventory solutions should still (mostly) work. Just encapsulate your properties in structs and pass the full struct into the inventory. Come save time, offload the array of structs into your save file.

Edit This does of course assume that there is some rhyme or reason to the way that you are doing your property variables.

So, would it look something like:

Item 1

  • If weapon use weapon struct with X data
  • If resource use resource struct with X data
  • If vehicle use vehicle struct with X data

Item 2

  • If weapon use weapon struct with X data
  • If resource use resource struct with X data
  • If vehicle use vehicle struct with X data

Item 3

  • If weapon use weapon struct with X data
  • If resource use resource struct with X data
  • If vehicle use vehicle struct with X data

And then having a different set of struct variables for every item slot? Or…

Hi,

good flexible inventory really hard thing to achieve in UE4 and i don’t know if any good exist on market yet, but i’ll try make one later

blueprints in UE4 yet have hard limitations to arrays, for example UE4 doesn’t support array of arrays, also seems no “map” like containers from C++ to make association arrays

Now little theory craft about core idea for flexible inventory items you want:

  1. you should have associated array of “stat name” and value type it can hold, for example name = string, level = integer, move_speed = float
  2. your item should have array of “stat name”+value of defined type from association array (it should prevent having name = “Cool item” and name = 10 at same time)

if you achieve this you’ll be able make flexible inventory where each item can have custom number of named properties and their values

in C++ there are tons of different containers lists, maps, vector… map best choice for association array
http://www.cs.northwestern.edu/~riesbeck/programming/c++/stl-summary.html

Watching your “brief” description I think that “maybe” would worth to try “standardize” your data struct to fit on both cases. While you could say that data will be different, some variable types could be “shared” and “read” with different contexts depending from the kind of object they’re describing.

So, instead of if from type X use data struct X1, if from type Y use data struct Y1…
Could be: if from type X read data struct A as X data, if from type Y read data struct A as Y data…

Probably you have “shared” properties (as name?) and to the ones that are different you can group by data type…
E.G. A Weapon need to point Damage (float) a potion is an item that needs to restore X points of life (float), a single float variable named Damage_HPRestore could be used to describe both items.

Just an idea… :smiley: