Download

I can't delete an object after loading

Hello everyone,

After I’ve managed to create a save system on my game, I’ve encountered a big problem: After loading a save, or changing level, my items (food or keys) reappears :frowning:
I’ve tried to create a system to delete each item when we pick them and save, but it doesn’t work …
I’m on UE4 V 4.15, and I’m planning to take the new version V 4.16.
Can anyone help me about this ?

Thank you in advance :slight_smile:

I’ve tried many other things, but without success :frowning:

Here’s some pictures, I hope it will help you:

This one should remove any item already taken:

9d1a9d8f5f396db277abe8b56fbd79813422f5f6.jpeg

and this one should set the array of the GameInstance:

0c728a3beacae4ed2e0169cdb5deca746cdb6404.jpeg

Any advices are welcome :slight_smile:

A few things to consider what you are doing in your BPs:

-You are using Game Instance to hold your variables. GIs (Game Instances) are persistent until the game closes. So any data set into them will be reset after closing the game.
-You are setting the bools to an array in your GI, but never referencing them.
-When your level is spawned, It seems that all of your “MAIN_Inv_Pickup” items are all running the same Begin Play event. In which, I imagine, that the default value of “IsTaken?” is set to false. This means that every time they are spawned, they spawn with the default values and nothing is deleted because everything is set to false.

I wish I was in front of my PC so I could be more specific, but what I would look into is save the variables to a Save Game. And instead of “Destroy Actor”, I would just hide it. You can use GIs for level transitions if set properly. But to avoid future issues with closing and reopening the game, I would avoid this.

And I’m sure people have a better more efficient way of doing this than my ideas, but I hope this helps points you in the right direction.

Thank you for your answer :slight_smile:

I finally made it ! I’m sure it’s not the most perfect solution, but anyway, I show you the pictures, for you to see:

When an item is destroyed, it does this:
2e5bb726253c06b003bd03fa62dfa8df95556ad5.jpeg
UE4 10.jpg

And in the Event BeginPlay:


And besides, when I save the game, IsTakenArray is saved to, and it works great :smiley:
So with that, each item doesn’t need to hold a single variable (I just need to set the length of IsTakenArray as long as the number of items presents in the game.)