It seems you can’t simply save an object reference.
I have an array of objects; an inventory. The array type is a base class for items, the actual instances are healthpotions, weapons, or whatever.
Of course, I want the inventory to be saved in the saved games and then loaded back. But I don’t know how you’re supposed to do it, since i can’t save objects (can i?).
What’s the best way (or just a way) of saving something like that?
i ended up just making a structure, in which i save the class of the item and the number of them (an item can also represent a stack of items, like multiple health potions in one slot).
i get the class via get class, on the actor. oh yeah, the items are actors. this is important, because in blueprints you can’t just instantiate arbitrary classes from blueprints.
i then added an array of that structure in my saved game. on loading, i use spawn actor from class with the loaded class for each item.
don’t really like this system. for example if i had an item that’s more complex, it would be difficult to get that to work. like a weapon that has weapon modifications on it or whatever.
there seems to be a sort of “archive” thing that can - if i understood that correctly - only be used from C++. seems like that can serialize things properly and that’s what the SaveGame-checkbox on variables is for.
is that correct, or can that type of serialization be used from blueprints?
I also would like to save my widgets. Whole HUD, like my Inventory with all my Items in it, or just separate Items. Items are just widgets with Images and some references and variables like int, string and some structures like LinerColor.
i’m in the process of trying to save game objects as well, and ran across this thread. you can create objects based on a class that don’t have to be actors. for example, if you create a custom blueprint that just extends ‘object’ class to hold a bunch of information, you can do that. then in another blueprint, to create an instance of that object, just use the ‘construct object from class’ node. this may or may not help your situation, but working with structs in blueprints can cause mayhem, so sometimes custom objects derived from object class are an alternative (since a class is basically a type of struct anyhow).