Is it possible to maintain an indexed TArray of actors without keeping it loaded in memory?

I’m working on my inventory system, and it’s split into two parts: the actual data, which is all that exists of an item 90% of the time, is a struct with nothing more than an ID number and a count. Accessory to that struct is a much more comprehensive class, AItemObject, which contains the item’s name, description, pointers to the desired static mesh and sprites to display it in menus or in-game, and the code to handle the player attempting to pick it up off of the ground. In theory, the idea is to save memory by only looking up desired data from an AItemObject at need, and making do with the ItemStruct the rest of the time.

Where I’m having trouble is figuring out how Unreal intends developers to store data outside of memory. The most rudimentary possible approach would be to make a class AItemDatabase which simply has an array of AItemObject, but that would result in the game always retaining one instance of every single item in the game loaded in memory, which is heinously wasteful. Storing data in excell and importing it as a CSV seems like another common option, but I would really like to retain the ability to edit my item database in the editor, so I could manually assign whatever mesh references and enums I end up needing.

So is there a third option I’m not seeing? It doesn’t seem like storing and retrieving objects by index would be that hard, but I’m not seeing many obvious options.

since you seem to have a working design in terms of the actual game logic already, perhaps the approach of making a simple editor plugin that let you view and edit your item database in the editor is a more feasible option. I have never worked on creating a plugin for unreal however so I don’t know how difficult it would be…

That might be smart, but it comes back to the question of what format to store and access it in-I know absolutely nothing about accessing external documents from unreal, and I’m concerned that shunting it all to an external data source would cause more problems than doing something unperformant inside of ue would.

Unreal really isn’t going to help you here much, so its pretty much roll your own storage. Sure it can handle serialization of objects, but just the basics. If you want some sort of database, or indexed table on disk I think you are going to have to do it yourself.

Hmm okay, that’s fair enough- thanks! I was mainly checking to see if there was an amazing, idiot-friendly tool I’d missed in my doc search :slight_smile:

If this is about storing the contents of an inventory to disk and retrieving it from disk in a new session, you can use SaveGames for this. You can’t store a TArray of actors using SaveGames, but what you can do is store is a TArray of actor classes which should work for you because items don’t change properties during gameplay. Is that what you were looking for?

Saving your game with blueprints
Saving your game with C++

You’re only storing pointers to objects in that Struct right? Not the actual data?

I found this in the doc by random, so turns out UE4 can read .xlsm and .csv you might be able to utilize it
https://docs.unrealengine.com/latest/INT/Gameplay/DataDriven/index.html