Forum rules - please read before posting.

Save game + container contents

edited December 2023 in Technical Q&A

I have an AC container with 4 slots, and it is displayed as a nest that can keep 4 eggs. Though the nest menu is only accessible from one specific scene, the container itself is a child of the player character (I need to be able to manipulate the items in the container even when the player isn't in that scene).

Eggs are a stackable item in the inventory and elsewhere, but in the nest in particular, I wanted each egg to take one slot. I managed to implement this with a custom inventory script that handles clicks on the nest container differently (selecting one egg and clicking on another won't stack them, etc).

Every in-game morning, I run a script that looks for an egg instance on each nest slot and adds +1 to their age property. Then it also looks for empty nest slots, and when it finds one, it adds one new egg instance to it - meaning the bird lays one egg every day, and we keep count of how old they are. So far so good. It all works perfectly including after scene changes.

The issue I have here is that if I save the game and then reload it, if there are two or more egg instances of the same age in the nest, then those instances will be combined into a single one and be placed in the first available slot. Eggs of different ages aren't combined (as intended), but they will still be moved to a different slot.

So if before loading I have a nest like this:

[Empty] [Egg age 0] [Egg age 1] [Egg age 0]

After loading, the nest will look like this:

[Egg age 0 x2] [Egg age 1] [Empty] [Empty]

Chris, could you change the Remember Container script to account for the exact configuration of the container?

Comments

  • edited December 2023

    I'll need to recreate the issue, first. What are your AC/Unity versions, and can you share screens of the Container's Inspector, the item, its properties, and your Settings Manager?

  • edited December 2023

    I'm using AC 1.79.2 and Unity 2021.2.7f1.

    Reproduction steps:

    1. Create a new project and add AC to it.
    2. Assign the 2D Demo managers and open the park scene.
    3. Check AC Game Editor > Settings > Inventory > Items can be re-ordered in Menus?
    4. Go to Inventory and check "Can Carry Multiple?" for the Worm item.
    5. Create a new container in the scene and add the following items: [Empty] [Worm (1)] [Empty] [Worm (1)]
    6. Run the Park scene, and using the Save Game Manager, create a new save. Notice how the worms are properly arranged in the container.
    7. Load the save you've just created and notice that now the container contains 1 stack of 2 worms in the first slot, i.e. they are no longer where they were before loading.

    Also note that in the Save Game Manager, under "Persistent data", the save does seem to keep the correct information saved (i.e. this is not where the stacks are merged). Something must be going wrong when restoring the container state.

  • Thanks, I'll see this addressed.

  • Open up RememberContainer and remove the code block:

    else if (!string.IsNullOrEmpty (data.collectionData))
    {
        Container.InvCollection.DeleteAll ();
    
        List<InvInstance> invInstances = InvCollection.DataToInstances (data.collectionData);
        foreach (InvInstance invInstance in invInstances)
        {
            Container.InvCollection.Add (invInstance);
        }
    }
    

    Then go up and find this line:

    Container.InvCollection = new InvCollection (Container);
    

    Just underneath, copy/paste:

    if (!string.IsNullOrEmpty (data.collectionData))
    {
        Container.InvCollection = InvCollection.LoadData (data.collectionData);
        return;
    }
    

    Does that resolve it?

  • Perfect, I've tested this in a few different scenarios, and the solution held up. Thanks for this!

  • Hey Chris, I've run into a bug related to this fix. Using the same project as above, after making the change to the Remember script:

    1. Limit the container by category 1. Assign the worm to category 2
    2. Open the container menu and try moving the worm into it. Notice that this action is correctly denied.
    3. Save the game, and then load it.
    4. Try to move the worm into the container again. Notice that now the item transfer occurs.

    I've checked whether this happened before the fix, but no, it didn't. The fix introduced the bug.

  • Thanks, I think I see the issue - I'll delve.

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.