Change DataAsset variable for specific DataAsset reference

Hi

So I’m making an inventory system, where items are using DataAssets for variables such as name, weight and amount etc.
I stumbled upon a slight issue which surprised me, whenever I change a variable in the DataAsset during runtime the variable is saved on that DataAsset in the editor.

This seems great if you want to store changes to items, but I’m using it to keep track of how many of an item I have and the weight of them. If this is intentional, i’ll defintively keep this method in mind of changing actor variables permanently during runtime lol…

Basically, when adding an item to the inventory. It stores the DataAsset reference in an InventoryArray. And if we already have an item of the same “ItemID” instead of adding another reference, it updates the existing item reference’s count and weight, so to “stack” them.

The problem is that every time i update the “count”, it updates for all items on the ground too, so next time i pickup something, it’s 2+2 isntead of 1+1, next time 4+4 etc.

So I’m definitively using these wrong… So what is the appropriate way to update the inventory stack of items storing only DataAssets?

I guess I could just add each reference to the array and then “stack” them in UI later, but seems like a bit of a hazzle…no?

Thanks!

Data assets are persistent, so yes, this is the intended behavior.

You should keep the data assets as data only definitions for the items, and then maybe think about creating an Item Instance from a definition like that, and have those instances be the runtime items in your inventory. If you are looking for inspiration, the Lyra project has a similar approach, although it’s all in C++

2 Likes

Hello! the easiest way is creating a instance of data asset, not a reference to data asset, you can do that by using node “Construct Object from Class”, so drag pin from your data asset - > get class → Construct Object from Class → add to your inventory, this way you can edit count of each inventory item.