Inventory saving between scenes / duplication problem

For practice, I’ve recreated the inventory example, but with my personal adjustments:

*I put all the code in an external event, and the inventory layout in an external scene. In the inventory code, there is code to load the external scene. This way, the inventory can be accessed from every linked scene in the game.

*I added an item that cannot be consumed when used. It only grants the effect without being removed from the inventory. Useful for reusable items.

It works great so far since it’s mainly the inventory example, but there’s just one problem…

The pre-made inventory example was supposedly not made with multiple scenes in mind.

I have two different scenes in my practice test, and a button to reset the current scene. If my inventory has one item in it, even if I didn’t save it, once I change or reset scenes and put the same item inside, it will display as two items.

Additionally, if I put an item in the inventory, save it, open a different scene or reset the scene, and then press load, then the item is loaded AND duplicated. However, once I press load a second time on the same scene, it changes back to the original value.

To test this theory, I went over to the ready made example, and added a button to reset the scene. I put two watermelons in the first slot, and then reset the scene without saving them. Once I put another watermelon in the empty slot, it displayed 3 watermelons. If you need to see this for yourself, just add a reset button to the example, and try it out.

So does anybody know how to fix this error? How can I make sure that the items can’t be duplicated when transitioning scenes or resetting the current scene?

My code is more or less the same as the inventory example, excluding the drag and delete code (I don’t need them).


Here’s a fix:

Woah, I can’t believe it was that easy! Thanks mate ^^

Although, I have one more slight visual bug going on. Whenever I use an item from the inventory, the text below each slot that tells you how much of an item you’re carrying goes missing instead of subtracting 1 (Well, okay it actually does remove the item, but the text vanishes for some reason). Once I put a new item in, the text shows back up. Since my attempt is similar to the example, I’m not sure what’s going wrong.

Here’s the whole code for using items:


If you want it to behave like in the example, why don’t you compare with the example? :slight_smile:
It’s made for that.
And don’t be afraid to try and tweak and try again.