can't understand why is not saving

So i need to save my Inventory which is an array of an actor object inside of a inventory component, i use this function to save inside the component:

After i load it with this function:

i save and load like this for now but i want to change the load function when i start the game and save when clicking an exit widget:

for debugging i tried printing the class, because its multiple class children of the same actor object, like this:

so the problem is after loading when i print the class its return me invalid, i tried building the function inside the player but its not working, i tried with struct but its not working either they all give me the same result. Any help is appreciated, thanks before :slightly_smiling_face:

PS: forgot to mention that the save game its the same as the one i use for saving player stats could be it the problem?

You can’t save object references. I mean, you can but, after loading, they will point at objects that may no longer exist… If you quit the game, they will definitely not exist. Those arrays do not contain actual objects - they’re just pointers to data in memory which will be released.


You can save those objects’ data once you pack them into structs - very similar to what you do with player stats atm. Once you load the data, recreated the objects.

i have already tried with structs but maybe my implementation was wrong, i created a BP struct and when saved the gave i setted the array item object pin of the struct to be the array of game object inside the component and when loaded i break the struct and set the value of the items array of the component to the value of the array item in the struct, this gave me the same result

As above, this will not work. You cannot save entire items because these are not items, these are just their memory addresses:

You can only save basic variables - floats, strings, integers, booleans… Combine them inside structs add those to an array, add arrays to the Save Game object and save to disk.


If you do not want to deal with all this, look into saving plugins.

  • so you mean i cant save the arrays of object as i set it up?

  • you have some plugin u would suggest me?

  • how can i save it if i dont look for some plugin, i would really appreciate if you could guide me in the right direction, after it i could try do it myself

    thank u :slightly_smiling_face:

There’s a ton of tutorials on YT:

https://www.youtube.com/results?search_query=ue5+save+struct

https://www.fab.com/listings/69e9c83b-50fe-4898-8297-b30f85d89c38

Or search for saving plugins.


so you mean i cant save the arrays of object as i set it up?

No, we cannot. @avuio Think about it this way:

  • there is a house (an actual object) and a piece of paper on which you write the house address down (the reference variable)
  • you go to sleep (quit the game), the house burns down (object is released from memory)
  • you come back tomorrow (load game), use the piece of paper (variable) to find the house and guess what… it’s not there
  • you will need to rebuild the house from the blueprints

sorry if i ask so many question but how i can do it, i thought of spawning the object after loading by getting its class but if when i exit the game the array is empty its useless, so i think i need to do it before, but i have no idea how

i have already searched for some tuts but i seems to be doing the same as i was, thank for your patience

You can save an array of (soft, optionally) classes. And that’s exactly how you’d do it. Good thinking! You could save an array of struts like so:

oh god :joy: im kinda new to unreal and this is a bit hard to comprehend for me but i think some sort of soft variable, like that:

not english, but the light blue one says “soft object reference”, thank you for your time im going to try get my head around it

1 Like

The purple would also work.

image

UE in non-English always looks so funky!

yeah :joy: always used it in english and i dont know why it setted it up in my main language anyway thank u for your advices

1 Like