So, i can’t give you a direct example with images, but i will try to explain it (you could watch the Epic Inventory Tutorial to see how they save the actors).
Instead of saving your items as structs (which is ok, but i find it rather complicated), you can make a Array that has your Item Base Class as type. So an array
of pointers (you might want to look up what a pointer is if you don’t know yet). With this, you can directly add the whole actor to the array and access the details
of each item the same way like you already do. Only that you are getting the actor and then the struct from him.
(Note: You don’t need to link every single entry of your Structs with the “Make struct” node. You could directly plug in the struct into the “Add” for your struct array setup.)
Now let’s say you have this Array of Pointers for you Item Base Class. You can save every Child BP, like Food, Weapons etc in this array without changing anything, because
pointers to base classes can also point to the children. You may see why this is an easier setup regarding different item types. Because you don’t need to create one big
struct with all different item information. You just need to create one Base Class with information they all share and then create children of that with the additional attributes.
Good thing here is to create an ENUM with “ItemTypes” for the baseclass. So that you know which item type you have and might want to cast to the child class.
(Note: If you save a child class, like food with additional details, in this array, you can only access the base class attributes. You need to cast it first to the child class to get the
variables and functions that this BP has. To know which item type you have, you can use the ENUM i talked about.)
Ok, so you have your array and now you know how you can use it to save your Items. What you want to do is: If you add an item to the inventory, you might want to set the
visibility of the ItemMesh to false and also disable collision, so that you can’t pick it up anymore. If you want to drop the item, you just need to enable collision, set the visibility
to true and may set its location to the drop point or something.
The function for adding should have the parameter i talked about. Just the BaseClass again. So you can reuse the function for all your adding you want to do at some point.
This point is, for example, your Shop. So how can you now get the shop to work?
You can also create variables with the real class (the purple colored one). Here you can set classes before starting the game, that can be used for spawning items.
Now, you could create an array of these classes. You can selected all the items that the shop should have. When selecting the item and buying it, you just take the
selected slot of the class array and spawn the Item. Then you can just use your Add To Inventory function with the new spawned/bought item and add it.
That’s all. :X
So something like that for your Add Item Function (just a small example. You will need more logic):
http://puu.sh/j73JR/d91f270102.png
And this is the Classes Array, but you can also choose the Item Base class, then you will only get the base class
and childclasses to select and not all actor classes:
http://puu.sh/j73Mg/9999f23e47.png
When the player selects an item, you can save the selected one and do something like this:
http://puu.sh/j73TS/32746b170c.png
You may understand that this is a high complex system and it takes time to create it, so i can’t show you more than this.
As i already said, you can watch the Epic Games Inventory Tutorial to get some ideas about the saving logic.