Problem when try to save Map Variables

Hy everyone!

My situation

I have an inventory that store Items and the “Quality” of that Item (Common, rare, etc).

I’m handling the save system by basic saving and loading a MAP type variable (Key:Item_Class reference | Value: integer).

The inventory gets the item class reference, spawn an actor from class and with the integer passed in the MAP, defines the item quality.

The problem with this system is that the player can only carry ONE item of the same class.

As the MAP keys needs to be the unique the existing value associated with the key will be overwritten with the new value.

One thing that I tried was to set the Key to a new Actor blueprint called Item Holder and this blueprint holds the Item class variable.

325736-print1.png

This way I can spawn multiple actors and call for the variable inside them when I need.

The problem with this approach is when I Save the MAP with the spawned actor and try to load it, of course, I get an Error because the actor was not spawned yet in that session.

Do you guys know any way that I can fake to the map or maybe just a way of saving the spawned actor without losing it’s inside information?

Hi KaioGx

If I am understanding your question correctly, what you are asking isn’t possible. Actor references just point to an address in memory. When the application closes, those memory allocations will be released and reassigned once the application restarts, therefore the saved reference will return null especially if you’re manually respawning the objects.

What I would recommend is adding some sort of custom identifier to the objects such as a GUID which is assigned to each object as they are spawned. Then store the GUID key and int value in the map. You will need to write a function that will then be able to find the object relating to the GUID when you want to access it.

Prehaps you can explain a bit more about what it is you’re trying to achieve with this system and I could offer some better suggestions for handling these objects. For example, what is the purpose of the int value in the map.

Good luck

Alex