Any idea why this saving and loading system isn't working for objects?

Hello, I’m following a tutorial on an inventory system and am having a problem with the saving and loading system. The issue surrounds spawning back in items which have been dropped from your inventory. Only 1 item at most will spawn and it will be much smaller than normal, getting even smaller each time you close the game and re-enter. Could someone take a look at these images and tell me if anything looks wrong?

Here’s the code in the game mode that loads in objects and saves the game:




And here’s the code in the actor I’m trying to spawn which adds itself to the save data level array and saves the game (I know this isn’t optimized, I’ll add a save button later):

2 Likes

You don’t need to save it here, you just loaded it, minor point

With the soft object references

Even if you use hard refs here, I don’t think it would work, because actor refs are a runtime thing, and may be different next time you run the game.

As for the soft class refs, I’d be very interested to see what you get in the ‘size map’ of your save game BP ( right-click in content browser ). I’m tempted to think it has all you classes loaded, might be wrong…

Thanks for responding! I’m new to Unreal but I’ll try and respond back

You’re right about not having to save there, I removed that, sadly didn’t fix the problem but that was expected

You pointed out the destroy actors code and the odd part is, that works completely fine. If you pick up an item, it will always be removed from the level upon loading back in, the issue is with spawning items which have been dropped by the player. I tried disabling the code that destroys actors and it didn’t fix anything so it’s not linked to that I think.

I’ve never checked out the size map before but here’s what it looks like when I right click on the save data level in case that helps:

And also here’s the tutorial I was watching, don’t expect you to take a look or anything but putting it here just in case: https://www.youtube.com/watch?v=bg0jJFdcTg8&t=332s

Thanks for the help!

The destroy actors works?! Amazing :slight_smile:

As you can see, even though you’re using soft refs, your save game class has loaded all your object types ( 700MB ). The point of soft refs is not to load everything, so your save game class should be a few K.

It’s not related to this size issue, but I’m just pointing out that this soft references thing is a bit of a minefield. And, no, sorry, I don’t really know the answer. I think even if you use ‘load asset’ instead of the implicit cast here

image

it might not help.

Ok then, is there a way you recommend to load in objects the player has dropped like I am trying to?

1 Like

One possible solution, is to make the save game a plain actor class for these refs

image

I can set it to my specific class, but the save game itself makes no assumptions

Sorry I might be wrong here but I think it is saving an actor class reference, although a soft actor class reference. Here’s the variable in the save data level:
image

You might be talking about something else though so I apologize if so

1 Like

Beg your pardon, yes. But it doesn’t need to be soft.

Somehow your save game is referencing your inventory system, that’s what clogging it up

Oh ok, I tried making it a not soft reference and it didn’t seem to help. I’ll investigate why it’s referencing my inventory system, thanks!

1 Like

None of this is supposed to be a solution to the scale problem, it’s just something you probably need to address before going much further :slight_smile:

I’ll take another look, with respect to the scale issue…

I don’t see anything. Is your inventory system changing the scale of objects anywhere?..

Oh yeah the scale thing is its own weird issue, I only included it because I thought it might be related. For the time being that’s not the concern. I think it’s related to the scale of actors not being 1 or something.

Also I changed it to a normal actor class reference and it crashed unreal lmao

Thanks for all the help but you don’t have to stick around if you have other things to do, I’ll keep trying to find a solution

1 Like

WAIT. I found why the save data level is referencing the inventory system, it’s this bit of code I completely forgot about:


This executes after spawning in the item the player drops. It seems redundant when this all happens on begin play for the actor when it spawns.

Weirdly though removing it doesn’t change anything, at least wanted to mention it

1 Like

I think there’s a reference to your inventory system actually IN the save game blueprint. It might even just be a variable type.

Yeah! Oh wait yeah you’re right there’s a variable for chests that uses a reference to the inventory system lol. WELL, atleast we know why now. And no it’s not good now sorry, I was saying yeah to you saying the size map would be better now

1 Like

It’s good now?

My current theory is that each time an item is saved it overrides the other ones somehow, it would explain why only one loads in at the most. Well gonna look into that now, thanks!

1 Like

If they’re all the same class, this

is only every going to write one line to the map.

!!! They are all the same class! So what here is specifically wrong? These are inside each actor to be clear. This is what the other person says so i think this really is the fix! I just gotta understand the problem because to me, I see a map variable with the class and transform of each actor being added to it so I don’t see the issue

1 Like

All the same class is good, it shows you have it organized, but a map is not the right structure.

You just need an array of structs ( actor class / transform ). ( or two arrays )

Ok gotcha I’ll do that, thanks! I have ONE more question though, if I use two arrays instead, how am I supposed to use those pieces of information to spawn the actors? Do I go through each actor and spawn it in with the transform of the transform array element at the same index?

Edit: IT WORKED

1 Like