Is this a good use case of using object pooling to avoid spawning/destroying actors?

I’m making a third person game that has 14 weapons in total, each with 1-4 attachments that have gameplay effects and show up on the weapon itself (scopes, extended mags etc)

The player can carry any number of weapons in their inventory if there’s space. When a weapon is unequipped it can either go on the back or the hip. (Think RE4 style inventory and system).

So at any point, there can be 1-3 spawned weapon actors on the character (one equipped and two unequipped).

Right now I’m spawning and destroying weapon actors when they are equipped/unequipped. But I’m thinking that an object pool would probably be a better solution because the player can hotkey up to 4 items. So swapping weapons with the hotkeys is essentially performing one destroy and 2 spawn operations every time (one to destroy the equipped weapon, one to spawn the same weapon but unequipped in the right slot, and one to spawn the new weapon).

I’m wondering if I should just keep all picked-up or in-inventory weapon actors spawned all the time? And just move, attach and make them visible instead of spawning or destroying them?

1 Like

Making an object pool is always a solid optimisation.

I would add if your “swapping weapons” (that are say equipped and not in your inventory) then spawning and deleting them that sounds wrong regardless of pooling the objects.

What ever reference you are setting for the new objects should just pass the values and not be spawning new actors in the case of a “swap”.

In the case of items in the inventory they obviously need to be spawned.

But when specifically “Swapping” the idea of destroying an actor then immediately respawning it sounds wrong.

Yes.