+1
Fixed

Inventory Container Bug

Eric Mathiasson 2 months ago in Inventory updated by Marti (Lead Developer) 2 weeks ago 3

I discovered a bug in the inventory module when using the container script.

When you loot all items from a container, switch scene, and open the container again, all items are back.

But if you remove all but one item and do the same, it works as espected.

Scenario (steps to reproduce):

  • Create a container and put some items in them
  • Play the game and loot the container from all items
  • Save game and transition to a new scene
  • Go back to the previous scene and open container
  • Container now holds all original items, as it was re-filled with the default items

I have not tried this with a Loot Table yet, only with pre-defined items in the container

Proposed solution:

File: GameCreator/Inventory/Mono/Container/Container.cs

Update the OnLoad() method to always flush the data variable before looping over the received items as such:

        public void OnLoad(object generic)
        {
            Container.Data newData = generic as Container.Data;
            if (newData == null) return;

            this.data = new Data();  // <--- Add this line

            foreach (KeyValuePair<int, ItemData> item in newData.items)
            {
                int uuid = item.Value.uuid;
                int amount = item.Value.amount;

                if (this.data.items.ContainsKey(uuid))
                {
                    this.data.items[uuid].amount = amount;
                }
                else
                {
                    this.data.items.Add(uuid, new ItemData(uuid, amount));
                }
            }
        }

This seems to fix the issue, since now, the container always resets whenever loaded data exists, and then gets updated with those items that should be there.

Cheers!

Eric

Unity version:
2019.2.7f2
Game Creator version:
1.0.2

Answer

Answer
Fixed

Fastest bug fix ever. You are 100% correct about clearing data property. Thanks! I'm marking this issue as fixed and it will be available in the upcoming Inventory update 1.0.1.

GOOD, I'M SATISFIED

Cool! Thank you for your work and good response! Keep on rocking that code! :)

Satisfaction mark by Eric Mathiasson 2 weeks ago
Planned

Hi Eric, thank you for letting us know! I'll open a ticket and get back to this topic once we start working on it. We're releasing the Shooter module this week an after that, we'll take some time to do maintenance work on the rest of the modules, including the Inventory. It is then when we'll fix this.

Happy game making!

Started

Hi Eric; Just letting you know that we've successfully reproduced the error (thanks for the detailed steps!) and we're working to find a solution and investigate yours. We'll circle back when we do.

Answer
Fixed

Fastest bug fix ever. You are 100% correct about clearing data property. Thanks! I'm marking this issue as fixed and it will be available in the upcoming Inventory update 1.0.1.