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):
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:
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
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:
You might be talking about something else though so I apologize if so
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
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
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!
!!! 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
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?