Filtering Inventory using an Object Pooler

While there was a thread about this topic, I am still having issues when filtering the inventory and using an object pooling method for better performance.

I have created a quick object pooler that is working ok, meaning it instantiates a bunch of needed gameObejcts, then when I need them I simply fetch them, then when they are not needed, they are being disabled and sent back to the object pooler, meaning their transform parent changes.

While I was using a local pooling method that @Brian_Trotter made for the ShopUI performance issues,
There was a problem if I used it for the inventory also.

If I used a foreach to go though the filtered inventory items, the inventory would get filtered correctly but, I was not able to move items inside it, meaning if I tired to move an item to an empty slot, it wouldn’t let me and it would snap back to its place. If I then tried to swap items in the inventory, then the item that was being dragged would get duplicated and the current item in the destination slot would disappear.

If I used a for loop to get the indexes, I could freely move items, without any duping issue, but, the filters would not be applied correctly. They were not working at all and it would just randomly turn off slots.

I really have no other ideas how to actually make this work with an objet pooler for better performance, because with the standard instantiate / destroy, opening, moving items inside the inventory when you have more than 20 slots would make the game unplayable.

Thanks.

Pooling the InventorySlots is easy enough… filtering is complicated, but doable… Unfortunately, these two great tastes do not always make a great candy bar…

I would recommend, rather than destroying the GameObjects on every OnInventoryChanged, only destroying and redeploying InventorySlotUI if the number of child objects (existing InventorySlotUI) has changed, otherwise just calling setup on the existing InventorySlotUI. When it comes to filtering, you could enable/disable them based on the filter.

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

Privacy & Terms