Portal Error

Hello,

I was just play testing after the last lecture and hadn’t gone through a portal since integrating the inventory system with the Core Combat course I completed before this course. When I am going through the portal i am getting the following error and am not sure what the cause it. I have checked the code against the repository and everything looks the same. What am I missing?

IndexOutOfRangeException: Index was outside the bounds of the array.
GameDevTV.Inventories.Inventory.GameDevTV.Saving.ISaveable.RestoreState (System.Object state) (at Assets/Asset Packs/GameDev.tv Assets/Scripts/Inventories/Inventory.cs:248)
GameDevTV.Saving.SaveableEntity.RestoreState (System.Object state) (at Assets/Scripts/Saving/SaveableEntity.cs:64)
GameDevTV.Saving.SavingSystem.RestoreState (System.Collections.Generic.Dictionary`2[TKey,TValue] state) (at Assets/Scripts/Saving/SavingSystem.cs:104)
GameDevTV.Saving.SavingSystem.Load (System.String saveFile) (at Assets/Scripts/Saving/SavingSystem.cs:57)
RPG.SceneManagement.SavingWrapper.Load () (at Assets/Scripts/SceneManagement/SavingWrapper.cs:60)
RPF.SceneManagement.Portal+d__8.MoveNext () (at Assets/Scripts/SceneManagement/Portal.cs:57)
UnityEngine.SetupCoroutine.InvokeMoveNext (System.Collections.IEnumerator enumerator, System.IntPtr returnValueAddress) (at /Users/bokken/build/output/unity/unity/Runtime/Export/Scripting/Coroutines.cs:17)

The IndexOutOfRangeException is the error that is showing in the Console.

It appears the game is trying to restore more items than the player has slots for (educated guess). Try deleting the save file and try again. If the problem persist, make sure that you have not changed the number of slots on the player in the scene and forgot to apply that change to the prefab. It could be that the player has 5 slots by default and you changed it to say, 10, and forgot to apply the change to the prefab. Now the player in the scene has 10 slots, but the player instance in the other scene still only has 5 - or vice versa

1 Like

This can happen if there is a mismatch between the number of slots on the players in the different scene. This makes it imperative that whenever possible, instead of editing the player within the scene, we select the Player prefab and make edits to that, to ensure that changes propogate back to the Core in each of the scenes.

1 Like

Ah…there was a mismatch there. Thank you both so much. Before I close this topic there is another bug that is giving me a problem. I have created more inventory items as Stats Equipable Items and they are working properly in the game but once I go to the next scene or load the game from a save the items sprites are not there but their stackable count is but if I pick up something else, even if it’s not stackable it goes into the available slot because the item isn’t technically there.






I actually found the answer to that in another thread. I hadn’t put those items in a resource folder so that they are available on load. Thank you both for your help on the initial question.

1 Like

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

Privacy & Terms