I’m trying to make an inventory that can store items with custom properties such as durability or maybe leftover ammos in a gun.
In my project items are stored in a DataTable that it self use a structure which have some basic values like name, icon, equipActor(actor classReference), pickupActor (actor classReference), quantity.
The Inventory it’s just a component with an array type of the structure that I mention before.
To hold an item it’s just spawning a new item actor with values from (inventory component → array Item Structure) and the actor get destroyed when change you item so you can spawn the new one.
Now the problem is that some items need some extra custom values like durability but as you can understand other items like wood don’t need it.
So if you have any idea how can I do that pleaze respond. (I have no problem rewriting the entire program if is necessary)
Some ideas I’ve already tried and failed:
Add all custom values to the sturcture for items.
At one point if I add to many values for different items it will be really hard to find anything and probably will have lag issues.
Changing the array in Inventory component to type of actor.
Two problems, I can’t have in chest default items with custom properties cause you need to spawn it first.
second all items need to be stored in a location of the map(this will cause lag issues)
Adding the custom values directly to the actor items.
Custom values can’t be saved when i don’t hold them because the actor get’s destroyed.
Why not just create a new struct that can contain the extra stuff you need by itself and have some kind of ID or dataname that can point to the datatable if you need it? So you basically would just have an array of structs that are Durability, etc, etc. This way you dont have to manage the default/base information for an item that youve already gathered that information for. You cant use datatables for values that will change at runtime so either storing them in an actor or array of structs is your best option for realtime changing values.
First of all thanks for answering.
You mean to create only one structure for all of the extra stuff or one structure for every item/(category of items) that needs it?
You’d be creating one new struct. But in your character or inventory system you would make an array variable of these structs that contain the realtime values for this system.
So in this struct will be variables of all different type of items that need custom values?
And variables like bullets, durability will be all in one struct?(Just double check to be sure)
Right. You could do this or spawn an actor that contains the same things. Either way you need your inventory system to have an array that contains these values. Whether in a struct or in an actor.