I created Data Assets for each items like weapons, collectables etc. And in the Data Assets i keep the informations that name, meshes, gameplay tag, descriptions. I want to create instance for each item and define price each one of them. Then I want to change price at runtime on game instance. How can i do that? I’ve tried to create game instance but can’t get data from Data Asset. What should i do?
Data assets are [usually] used for the definitions of the items, not the reference of the item in the world. Your actual physical items in the world (or on the player, or in a save game) should usually be stored in a raw data system, with as few variables as possible, and stored as an “item slot.” The item slot then specifies that it uses that data asset as it’s “item type”, and whatever other dynamic variables needed (quantity, etc.)
I’m not sure what your plan is for pricing, but does it have to be per item? Usually a global price modifier works best.
The data asset would store a “base price” which never changes, and then everything bought/sold on a vendor would use a multiplier. I.e. if your character has a discount at the vendor, everything might be multiplied by 0.9 (10% discount.)
Individual prices would work fine if you want to store it in the item slot as well. Generally an item slot is just a struct (in an array), or something simple as possible.
First of all, thank you for your answer. I’m trying to develop a store management game. I plan to buy items from other vendors and sell them in your own shop. And you can change the “sell price” in your inventory and put them on the shelves so AI NPCs can come, take and buy with your price (not the base price). Because of that, it has to be per item.
I create a Primary Data Asset, and it has variables like name, type, description, static meshes, and thumbnail images. So when I add a new item, I create a new Data Asset and choose the parent class this PrimaryDataAsset. I chose the mesh from the content folder and filled in the other parts, and it looks like DA_Weapon1, DA_Weapon2, etc.
I’m a little bit confused right now, what should ı do? A lot off topics says i should go with instances, but i Don’t know how to do it.
ill recommend using a data table instead of data assets.
they are somewhat interchangeable, but a data table can be modified and saved at runtime.
as well as are able to be imported and exported to csv and json.
the other benefit of a data table is that you’ll end up creating a struct, like wrex suggested.
and you can create variables for that struct as many times as you want, so you can keep track of runtime instances even without using the data table. for temporary values for example.
if your items prices are going to change wildly, as there are 5 items that are technically the same, but then you buy and sell them for different prices at different places. then you might have better luck with a custom subsystem that can store and persists these combinations. though something like an inventory could do.
primary data assets server other purposes iirc. don’t confuse them with data assets.
i think you should ideally break down the mechanic in several pieces and separate them, that way you can understand it better. as of now it sounds like you’re mixing several steps together and causes you confusion.
good luck.
benui gives a bit of unfair bad rap at data tables (and ue), but data tables are pretty amazing.
for an example here’s my free and open source inventory plugin, it uses data tables.
and this is the struct i use for items
as you can see it has a few variables at the bottom marked as “transient”. i change those at runtime. i keep instances of that per acquired item.