Equipement isn't saved during portal and freeze

Hello.
After having delete the capture and restore state in fighter and add the invoke in the equipment script, Equipment isn’t saved and crash during portal.
It looks there is an error in the inventory script :

the script line in inventory script:

void ISaveable.RestoreState(object state)

        {

            var slotStrings = (InventorySlotRecord[])state;

            for (int i = 0; i < inventorySize; i++)

            {

                slots[i].item = InventoryItem.GetFromID(slotStrings[i].itemID);

                slots[i].number = slotStrings[i].number;

            }

            if (inventoryUpdated != null)

            {

                inventoryUpdated();

            }

        }

it’s this one:
slots[i].item = InventoryItem.GetFromID(slotStrings[i].itemID);

I try to re-add deleted line in fighter capture and restore, it fixes the freeze bug using portal but my equipment deseaper.

I always have an index out of range:

Do I missed something ?
Thank you.
François

It looks like your inventory size may have changed between saves… (or may be different on the Player in scene 0 and the player in scene 1 most likely).

So if the player in scene 0 has an InventorySize of 16, but the player in scene 1 has an inventorySize of 12, then the player is going to be saving 16 slots but restoring to an inventory with 12 slots… That error would actually fire on the next line

 //This would cause an out of bounds when i=12 because slots[] is a 12 array
slots[i].number = slotStrings[i].number;

On the other hand, if the inventory was set to 12 in the first scene and 16 in the second scene, then you would get an out of bounds error on the previous line

//This would cause an out of bounds when i=12 because slotStrings would only contain 12 items.
slots[i].item = InventoryItem.GetFromID(slotsStrings[i].itemID);

That makes it extremely important that all of your player gameobjects in each scene have the exact same number of inventory slots at all time. This is best enforced by ensuring that none of them override whatever value is in the player prefab. Then you’ll only make changes to the prefab. Note that any changes to the inventory size even in the prefab will make any existing save files invalid.

Hello Brian.
Thanks for your reply.
It was that :slight_smile:
Master Brian :wink:
Thanks again.
Have a nice day.
François

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms