Download

Storing persistent data

I’m trying to figure out an inventory system.
I’m currently using Data Assets as the base item class, then i have an actor class for anything that needs to physically spawn, i.e world mesh, visible equipment ect.

I’m trying to figure out how to persist data say when an item transitions through the game, as in; From the world to the player inventory and back.

The data assets are read only, data only. But every item is inherited from the same data asset.

Current solution is to just store any persistent data in the item default struct that is exposed to all child data assets, that way i can just assume that all the data i need to persist is there.
But that just convoluted the base item, i’ll need a tonne of variables for specific item classes that others don’t need. For example, an item type resource doesn’t need to know about ammo, but a weapon might.

AActor (World Item)

  • Item Type {Enum}

Weapon {Parent World Item} [Item Type: Weapon]

  • Weapon Type {Enum}
  • Weapon Name (name | string]

Data Tables
Weapon (all data needed that you want easily updated]… e.g. recoil, sway etc.

On pickup get data table row by name (weapon name).

World placed items I use simple actor class with low data and a static mesh. For skeletal weapons I use a robust actor, high data, sk mesh…on pickup


For the inventory itself I have a Struct for weapons. The struct has an Weapon class Obj reference for each slot (Primary 1, Primary 2, Secondary). I also have a struct for ammo, throwables, consumables etc.

If the item will not be attach to the pawn its simply data and the struct element reflects that. Typically an Integer for quantity.
e.g. Ammo {556: 200, 9mm: 0 etc etc for each ammo type}

inv_weapons

Yeah i’ve got most of that. The issue i’m having is scalability. Each new type i want to create, or variable i need to track i need to add behaviour for it, or add it to a universal struct which would end up being quite massive and convoluted.

So ideally i could use an array of a base items, but still retain the ability to track item type specific data that needs to persist, but without adding it to a ‘one struct to rule them all’

I create a child class for each “Type” of item. In the class I create the “specific” structs etc for it.

For example lets look at weapon again.

World Item {AActor}
Weapon {World Item}
Wep_SK-AK47 {Weapon}

The Weapon class is the parent for Wep_SK-AK47. It contains all the structs, vars, logic etc for the weapon. An example of this would Recoil struct, Weapon Type {enum: pistol, smg, lmg, ar, sr, dmr, shotgun etc}, IK offsets, base weapon config(ammo type, mag size, muzzle velocity and so forth).

A throwable (aka frag, smoke, flash) would have a different parent class… Throwable {World Item}. It would contain all of its own logic and variables.

Both of these read from a specific data table on begin play to fill in specs, icons etc.

Weapons → Weapon data table
Throwables → Throwable data table

I get that, But how would you go from an actor, to a data orientated object that sits in an inventory, which can then be “dropped” into the world again, and retain information about itself like durability.

I can put something like durability on the base item easily enough that i can just transfer structs between the world actor and the inventory object.

But it falls apart when you need to track say, ammo on a weapon, quality on a piece of armor. But the armor doesn’t need to track ammo, and the gun doesn’t need to track quality. Then scale that up between different item sub types, like consumables, resources, quest items ect. There’s going to be a lot of variables that all items would use, but there’s definitely going to be edge cases where a variable needs to be tracked for one item type only.

I’m assuming each item dropped will have an actor reference in the rendered world. Mine does.

When I drop a vest/helmet I destroy the attached (high data) and spawn a low data variant, lower poly sm etc. I update the newly spawned vest with any relevant values (exposed). Durability (float), Skin (enum reference) etc. Server does this of course.

On pickup action the server will grab values from the vest/helmet, destroy low data actor, spawn high data, do a data table look up, set the base values, then overwrite with grabbed values, attach to character etc.

Re-read my previous post. I have a child class parent for each TYPE of item. All weapons derive from Weapons class, Throwables from Throwables, consumables from consumables. The Base parent class World Item only contains variables and logic that ALL world items will use. Weapons do not have a durability float, armor does not have recoil, weapon type, ammo type variables/structs.

When I need to add a new weapon I duplicate an existing one, then tweak base variables in class and add an entry to the data table for weapons. Same for Vests, helmets, meds, throwables, ammo and so forth.