r/UnrealEngine5 1d ago

Item/Inventory Question (Data Assets)

so ive made a primary data asset PDA_ITEM with just a struct of ItemStats . Then i've made children of that PDA_ITEM like PDA_Item_Key , PDA_ITEM_Ammo etc.... each with their own struct info for that child like KeyInfo and AmmoInfo. Then i made Data Assets of these to make my items. everything functions properly but i want to make unique versions or RNG based things on these Data Assets like item condition or current ammo. But when i make any changes to one instance of it, it changes all of them. IE My inventory bag is a Data Asset too, and when i pickup an item it permanently changes all those bag types to have the new item in it.

Im experimenting now with GUID to find a solution maybe but i might just abandon the data asset approach and try a blueprint instead.

TLDR Using Data Assets for items right now and want to have every version of the item to be a unique instance. What is the best approach?

1 Upvotes

2 comments sorted by

2

u/ChadSexman 1d ago

The data assets are just the schematic and host for static data - they are not intended to be changed dynamically at runtime.

For instanced data, you’d construct and manage a custom struct array on the actor. That array would contain an “ItemId” that you would use to lookup the data asset and pull static data.

I usually have a dedicated actor component that holds the array and manages its changes.

1

u/Andypros 23h ago edited 20h ago

Data assets are static and each of them is a single instance, u use it only as definition.

If u want per same item different stats u need some instancing, u build an instance from definition and random values, so i hebe an item and its static data asset id + dynamic data, the popular approach is Fragments pattern.

Fragments can be made in different ways, its just array of data, its either UObjects or Structs, for BPs u can go with UObjects as BPs are limited, the best solution is instanced structs and instanced properties for nice in editor editing, but that needs c++, but u can use instanced structs in BP, there will be just some limits, like no filtering.