Inventory System Save System - One Object Spawns on Play After Being Destroyed

I’m following Ryan Laley’s Inventory System Tutorial, and this is something I haven’t seen him cover, which is the fact that if I create a second type of object to collect in the inventory, the object being destroyed doesn’t save when I open the game again.
So my question is, how do I get the second object to save after it’s destroyed and not reload in when I start the game up again? (the second object is the key and the first is the seashell. The seashell saves it’s destruction just fine.)

Code: Library | Loom - 6 January 2025 | Loom
Gameplay: Library | Loom - 6 January 2025 | Loom

the key and the seashell should be a child of the same parent pickup actor?

if so it will work unless you’ve overwritten something in the child, for instance BeginPlay, make sure you Add Call To Parent Function

2 Likes

Because I don’t want my players to be able to drop items, I skipped the part of the tutorial that lets you drop them (you may destroy them in your inventory instead) because of that I had to find a different way to do what he’s doing here

This is what I have instead for the code, it doesn’t work, I tried to adapt it to what I’m doing but its not working.

To my knowledge the key and seashell have the same parent and all and it calls the parent function on event begin play so… not sure why it isn’t working.

its hard to follow that without knowing the full context so a few thoughts

  1. never use GetActorOfClass, you dont know what actor that will be
  2. if you’re removing from inventory whats the map you’re adding too? if its a map of objects that have been picked up? if so then it should be on pickup not remove?

I assume this logic is in the PlayerPawn?

Yeah, I figured using GetActorOfClass wasn’t the right move, I’m just really am not sure what to use. When they are destroyed, the item is destroyed (demonstrated here)

And here’s the code for remove inventory (although I don’t think it’s related to the problem, I could be incorrect. I fully followed the tutorial for this part though)

The logic is in an actor component I’ve created based on the tutorial, the bulk of the logic for the entire system are made up of different functions inside the component.

but your issue is the item in the world spawns when it shouldn’t?

show me the logic of where you handle that

1 Like

This is the logic that’s meant to save the removal of the key from the world.
It works on my seashell items, but not the key item.
And this is the logic that happens when the game is started up again and is told not to spawn the objects that have been picked up.

your logic looks fine,

it seems the only relevant detail is the ActorsRemoved Array

so on pickup make sure its added to the array with a PrintString

and on your destroy loop print the names of the objects being destroyed

1 Like

I tried my best to follow these instructions, I don’t know if this is what you’re asking for but I tried:

It looks like one of my seashells are also not destroying as they’re supposed to.

try a print after the IsValid check?

i’ve not used this system but you’re using soft object references? my understanding is there is no guarantee the objects would have the same object reference the next time you load, meaning the value wont pass the IsValid check?

if so i’m surprised Ryan used this method, but i could be wrong

1 Like

I had this same issue, I think it ended up being that I needed to clear the map/array in the saved game before setting it from the inventory component

1 Like

The soft reference was what he used, I’m pretty sure this is the soft object ref you’re referring to.

And here’s the string after IsValid?

Do you have a visual example? If not that’s totally fine, I’m just wondering if you have a BP I can look at.

Yea I’ll post some screens tonight after work

1 Like

it looks correct so lets change focus, are you possibly adding/spawning a duplicate?

check the ActorsAdded map

Here are all of the places that I use my actors added.

Actually, for the game mode begin play, when I remove everything after the complete loop (so actors added ‘keys’ and onward) The issue seems to be resolved, but in the future, I may want to utilize the add actors array, and I don’t know if this is a sustainable solution.

For this one, it’s odd because I don’t want the actors added to the scene so I’ve skipped past that step, but I’m not sure if I am doing that wrong. Not sure if related though at all. This is the only area place I would have added anything to the Add Actors array though.

aha so we finally found it,

you can search you’re entire project to see if there is an ActorsAdded somewhere else, this is also a good lesson on why you should encapsulate that logic in functions.

but also if you ever Add an actor you must remember to remove it on pickup/destroy

So the blueprints above are ALL the places I put the ActorsAdded array, so I’m unsure what I’d be searching for. I am having trouble understanding what is the course of action at this point in fixing this issue, I’m sorry

so whats happening is your destroy function is working as intended but you’re spawning a duplicate on ActorsAdded.

we know this because when you Remove ActorsAdded it works.

the only place you have ActorsAdded is on Inventory Remove, which makes no sense because you said you dont want to drop items?

at this point in your project is there any reason to have ActorsAdded at all?

1 Like

Oh, I see- my apologies for not understanding at first.
So right now I do not have a use for actors added, though I will need it if further in the game an item spawns for the player to pick up. When I remove all parts of the code for actors added, specifically in the Event Begin Play on my game mode, it seems to work accordingly. I don’t know how to fix it so in the future I’d be able to add actors without unwanted actors spawning, though.
I’ve also removed the actorsAdded from InventoryRemove but it doesn’t seem to have any effect.