[Released] Pure Pool - Serialisable High-Performance Object Pooling

Unity 5.6.1+ (including latest releases of Unity 2021)
Cross-platform: All platforms supported - Windows, Mac, iOS, Android, Universal Windows Platform, Web, Console, and more

Pure Pool is a professional and extensive object pooling solution, designed to improve the performance of your game. Simply replace Instantiate and Destroy calls with Acquire and Release, and enjoy a smoother gameplay experience. It offers object pooling for every device: Desktop, Laptop, Tablet, Mobile, Console - it fully supports all Unity platforms.

Integration libraries are included for UNet and Photon Unity Networking to help you utilise object pooling in your networked game, as well as a library with PlayMaker actions.

What’s more, Pure Pool is the only fully-serialisable object pool for Unity. Pools, all of their settings, and all of their statistics, are all serialisable. Make the most of Unity’s ability to hot reload code (also called live recompilation) for rapid prototyping and iterative development, without losing your pools in the process.

Designed for performance all the way through, even EventArgs objects used in the raising of C# events are internally pooled by Pure Pool. Garbage generation is kept to a minimum or avoided entirely where possible, reducing the need for the garbage collector to run, and allowing you and your players to enjoy a stutter-free and smooth game.

Features:
Serialisable High-Performance Object Pooling
Custom Inspectors - pools and managers have their own inspectors to maximise usability, supporting drag-and-drop for quick setup
Pool Organisation - give names to pool containers in the hierarchy and nest them to keep your pools tidy, and easily findable - or search from the custom inspector with basic regex
Runtime Statistics - get runtime access to pooled object counts, instantiation and destruction counts, elapsed times, and more, for tweaking performance to the max - or view them in the inspector
Pool Definitions - your pool’s settings are immortalised into a pool definition when initialised, so when you make changes at runtime in the editor, you can easily compare your changes to how the pool was on start-up
Easily Disabled - a toggle button in the inspector, also available through code, lets you test your game without pooling and compare performance, and helps pinpoint bugs
Simple but powerful API - create, modify, and organise pools and pool managers at runtime, and monitor statistics through the in-depth API
Serialisable - maintain settings and pooled objects after an assembly reload caused by live recompilation, allowing for quick iterative development without long downtimes
GameObjects and Custom Classes - pool any GameObject, or your own custom C# classes
Supports All Platforms - including AOT platforms
Integration libraries:
PlayMaker Support
Unity 5 Networking (UNet) Support
Mirror Networking (UNet replacement) Support
Photon Unity Networking (PUN and PUN 2) Support~
Photon Bolt Support
Full C# Source Code - Visual Studio 2019 solution included
XML documentation - .xml documentation files included for Intellisense in Visual Studio
API Reference and Documentation

Website
Documentation
API Reference

Release Notes

Version 1.8 (2020-07-09)

  • Added an integration script for Photon Bolt.
  • Added an integration script for Mirror Networking, a replacement for UNet.
  • Improvements to the included PlayMaker actions:
  • The “Acquire Game Object From Manager” action no longer needs the Prefab to be stored in a variable, and the Prefab and Parent values default to “Use Owner”.
  • The “Release Game Object To Manager” action no longer needs the Instance to be stored in a variable, and defaults to “Use Owner” - useful for FSMs that are on the prefab (and releasing the pooled copy).
  • Added a new action “Release Game Objects To Manager”, that releases an array of GameObjects to their appropriate pools.

Version 1.7 (2020-06-14)

  • Added two new PlayMaker actions: AcquireGameObjectFromManager and ReleaseGameObjectToManager.
  • Added Add and Remove methods and a ComponentsToReset property to PoolableMonoBehaviour, to allow programmatic modifications.
  • Bug fixes for PUN integration scripts, and additional error logging.

Version 1.6 (2020-06-07)

  • Simplified the out-of-the-box usage of Pure Pool. The “Debug (Editor)” configuration has been removed, and both Debug and Release binaries can be used to make builds. The default binaries used are Debug.
  • Improved the PUN integration scripts, including bug fixes for PUN2. The integration scripts are now serialisable, ensuring PUN pooling survives an assembly reload.

Version 1.5

  • Fixed errors relating to the deprecation of Unity Networking (UNet).

v1.4 (2019-08-27)

Version 1.4, first offered to Asset Store users on August 27, 2019.

  • Added integration script for PUN 2.
  • Bug fix for EventArgsPool error on iOS (and other AOT platforms).

v1.2 (2018-01-31)

Version 1.2, first offered to Asset Store users on January 31, 2018.

  • Bug fix for PUN spawning not respecting position and rotation.
  • Bug fix for DontDestroyOnLoad causing error messages.

v1.1 (2017-07-03)

Version 1.1, first offered to Asset Store users on July 3, 2017.

  • Added an overload of the Release method that accepts a float delay as a parameter, to mirror the overload of Object.Destroy that takes a delay.
  • Fixed the location of the PrefabPool.cs PUN integration script, which should be outside of the Plugins folder by default.

v1.0 (2017-06-15)

Version 1.0, first offered to Asset Store users on June 15, 2017.

  • Initial release of Pure Pool.

Hey, stumbled across your asset when looking for pooling solutions for mirror. I looked through your documentation, but there seems to be no info on mirror integration or unet in there. Could you maybe explain how to implement in a mirror setup?

Hi there!

I’m working on adding some documentation for the Mirror integration, which can be found here:
https://www.umbrace.co.uk/documentation/pure-pool/mirror-networking/

There is only a single component that needs to be added to your scene to support Mirror (MirrorPooling), and it should be connected in the inspector to the GameObjectPoolManager. Beyond this, for most situations you should only need to call NetworkServer.Spawn or NetworkServer.UnSpawn for Mirror to take advantage of the pool for spawning and unspawning.

Cheers,
Mark
Umbrace

Thanks for the reply, this sounds like exactly what we need! will probably be back with more questions soon.

Hello again, working on integrating the purepool asset in our mirror project right now, but we have 1 stumbling block so far. Using the Unspawn method on the spawned gameobject (using the mirrorpool integration) doesnt actually return the object to the pool (as in reparent it, and it’s not available to use again). could you offer any insight on how to use this properly?

I’ve been doing some testing and have updated the MirrorPooling component - can you try replacing the existing MirrorPooling.cs file in the “Assets\Plugins\Umbrace.Unity.PurePool\Integration Libraries” folder, with the one attached to this message?

It’s also important to note that you should pass an instance of a GameObject, not a prefab, to the NetworkServer.Spawn method, like so:

GameObject instance = GameObjectPoolManager.Instance.Acquire(this.Prefab);
NetworkServer.Spawn(instance);

When you unspawn, if the instance was acquired on your client, you also need to return the instance back to the pool:

NetworkServer.UnSpawn(instance);
GameObjectPoolManager.Instance.Release(instance);

For other clients, the call to UnSpawn will propagate to them and automatically release their instances back to the pool.

7204177–865240–MirrorPooling.cs (10.5 KB)

Hi again, I actually managed to get it working with the original integration library, neatly pools, spawns and unspawns objects on all clients and server!

Hi again, another quick question. Currently, we have our objectpooling set up in the main gameplay scene, which works fine when testing and spawning players directly into gameplay. However, when we test the actual game loop, we notice that several, but not all of our pooled objects fail to register, because they have an empty asset id. No clue why this would be empty, when checking the prefab outside of play mode they do have an assetid.

Any idea as to how this can happen, or how to fix it? also, do you have any tips or guidelines on when to actually register the prefabs for spawning?

If you’re loading any of the prefabs from asset bundles, you might be running into this issue: https://github.com/vis2k/Mirror/issues/2765

There was also a recent pull request to improve assetId assignment, here: https://github.com/vis2k/Mirror/pull/2781 - but it hasn’t been merged yet.

If the asset bundle issue is not relevant, I’d suggest contacting the Mirror devs to help troubleshoot what’s causing the assetId to be empty. Unfortunately I don’t know what could cause that to happen, but they should have a much better idea of what could be going wrong.

As for when to register the prefabs for spawning, I think that’s largely up to you. As long as you register them before you use them (on both the server and the clients), any time should be acceptable.

Any sample for PUN2 integration?