Problem with Items equipped, Enum
Hi guys and gals, I'm in need of your help once again. This time I made a short video illustrating the problem because it's difficult for me to explain when typing.
This is the UI_Equipment widget script to update the slots:
asked Jun 04 '17 at 04:38 PM in Blueprint Scripting
I think I see the problem: You are doing a foreach loop on the equipment array. I am not sure what you keep in that array (items you already equipped would be my guess) but whatever you are doing it gets done on ALL the objects in that array.
My guess as to what is happening: it starts with rifle: because rifle is already equipped it puts it into the secondary slot with 99 amount. Then it puts the grenades into their respective slot.
In effect you are putting all equipped items into the UI ONE MORE TIME. If you want to go this way I would recommend clearing the UI first (remove all equipped items from UI and reset the variables) and your function will add them all again.
The right solution would be different though. Keep the reference to the newly added item, and pass only that item into this function. This way it will be run only 1 time and will add the item into a free slot, without going through all equipped items.
EDIT: Quick fix: instead of iterating over the equipment array, add an input to your createEquipment custom event and pass in an array containing only the one new item you are adding to the inventory. Subsequently do your foreach on this custom event parameter array instead of your existing whole inventory array)
Follow this question
Once you sign in you will be able to subscribe for any updates here