Hi everyone! I am experiencing a strange error that throws when I try to equip specific weapons from my inventory that states 'an index was out of range. Must be a non-negative and less than the size of the collection." What confuses me about the error is that I havenât changed any code or moved the hierarchy around in anyway so I am unsure of why the error is being thrown all of a sudden. Any helping hands you guys can lend would be very appreciated!
What is also strange is that I only get the error while trying to equip the Axe and the Glock, but the Flashlight works fine. I should clarify that these weapons are connected to separate arm meshes, they are children of the player character âSedgewickâ but can be moved to and away from the parent. When I expand the error it leads me toward my GAMEUI prefab, which holds all of the games UI elements and scripts for important systems (save, load, etc.) I do have an Inventory script attached to it as well but when I search through it nothing seems out of the ordinary or different from how I had it before when it was functioning properly. I though maybe the negative values attached to the item switcher script within my player character might be causing the problem, but nothing changes when I switch them out for a positive or nil value.
Diving into the code highlights these lines on these specific scripts. This where I am super lost I myself, am not much of a programmer and cant make sense of what is wrong. Again I donât see how something could have gone wrong with the code if I have not changed it, the only big change to the project that comes to mind around when i started experiencing the error was installing a preview memory profile package, but Iâm unsure how that could cause this error specifically.
Iâd be happy to provide anymore materials you guys need to help me crack this error, its been such a pain especially since I just cant pin point what exactly is going wrong.
Thankyou!