Would it be worth using an object pool here?

I’m wondering if we can have the best of both worlds by using an object pool instead of destroying and recreating the slots. That way we can have the clean redraw of the entire inventory, and also avoid giving the garbage collector a lot of extra work. Or is the performance hit for this sort of thing so neglibile that it’s not worth making the effort? How do you determine when an operation like this is worth optimising performance for?

Thank you.

Actually, this is one area where object pooling would significantly improve performance, at least with the Garbage Collector. Lots of changes quickly in inventory can add up real fast… a 20 slot inventory with 10 or 12 items rearranged would lead to 200+ Destroy/Instantiate calls.

1 Like

This is a good qustion. It really comes down to whether you see it impacting the game experience. When a character is sitting idly, a frame rate drop doesn’t matter and would be a waste of time to solve an unnoticable performance hit.

If this action would be used in a boss fight, where heaps will be going on at once and it could cause the game to drop frames at a critical moment and cause your user to nerd rage at your game, you’ve found a great spot to work hard to optimize.

Anything between is a judgement call based on what the effect to the user would be and how many resources you have available to put into the problem.

2 Likes

Privacy & Terms