How to use object pooling?

In other game engines, object pooling is creating lots of objects at the start of a scene, then reusing them instead of destroying them. How can you do that with Defold?

This practice is not necessary in Defold. It’s automatically done for you. The reason why it’s automatic is that in your game.project you set the max of everything you want, and then those are reused.

Create/destroy objects at will. There is no issue for this in Defold.

4 Likes

As @Pkeod says there really is no need to manually pool your objects. I created an example a long time ago that shows this: https://github.com/britzl/publicexamples/tree/master/examples/pooling_vs_creating

1 Like

Is there a performance hit in setting really high limits in game.project?

It will allocate more memory. But if you set 10000 as limit and use only 10 it would not traverse all 10000 so from an update perspective there shouldn’t be any difference.

4 Likes

A recommendation is to never set higher limits than you know that you will use. Use the profiler or make manual calculations and then set limits based on your findings.

3 Likes

Thanks, that’s a great idea!

1 Like