Search Unity

Utilities Compositional Pooling System - Efficient and Easy to use pooling system for game objects

Discussion in 'Tools In Progress' started by M-Mahdi, Sep 30, 2021.

  1. M-Mahdi

    M-Mahdi

    Joined:
    May 7, 2021
    Posts:
    8
    Are you hesitant about object instantiation? Do you fear the performance implications of object destruction? Do you hate plaguing your code base with optimization efforts?

    Then, compositional pooling system is what you want. It is the ultimate implementation of the object pool pattern and it is as effective in eliminating these problems as it is easy to use.

    All you need to do to integrate the system into your project, is to replace all desired Instantiate/Destroy calls with PoolingSystem.Request/PoolingSystem.Release and the system takes care of the rest. There are no interfaces to implement, no base classes you have to derive from. You don't have to make any other changes to your project. In fact, you don't even have to do any configurations or setups for the system to work.



    The system disassembles the objects you throw at it and breaks them up into their core pieces. It is the reassembly of these building blocks that provides you with your requested objects. This is also why the system is very efficient at what it does as it reuses every piece of the objects over and over.



    The setup process although non-essential, helps optimize the performance of the system by providing it with what it needs to reuse the objects. It involves writing some object mapping logic and it is very simple if you checkout the provided examples. You can do it by hand or let the provided editor tool to take care of it in a blink of an eye.

    Alright, no more talking. The system's core source code is available on GitHub at this link. It is mature and ready for deployment. It does lack the editor tools but that's also what makes it ideal for the learning process. Try it yourself. Did you like it? Its full version (core + editor tools) is going to be available on the asset store soon. Until then, feel free to use it for personal projects.
     
    Last edited: Dec 24, 2021
  2. one_one

    one_one

    Joined:
    May 20, 2013
    Posts:
    621
    Will this be compatible with unity's new built-in pooling system? Looks like a well made asset either way.
     
  3. M-Mahdi

    M-Mahdi

    Joined:
    May 7, 2021
    Posts:
    8
    To be honest, you won't need any other pooling solutions (including and not limited to Unity's built-in pooling system). Unity's built-in pooling system is only suited for pooling plain C# objects like collections and lists and yet it is subject to some general limitations (e.g. when you unpool a list collection, it might not be of the capacity you want). Compositional pooling system on the other hand pools game objects and does that quite well. Although it only pools game objects directly, it can pool any other objects transitively. I will explain this in the usage guide. For now, it suffices to say that the object mapper delegates required for setting up the system, enable custom pooling logic like resetting the objects owned by the components (e.g. clearing the C# collections on each pooling cycle). Since all objects in a Unity project are in one way or the other, owned or controlled by the components (Components are where the execution of code begins after all), this not only means that the compositional pooling system can pool all objects but also that it pools them much more effectively thanks to the localized pooling logic involved. Nevertheless, if you still want to use other pooling solutions as well, it is trivial to say that it is fully compatible with any other pooling solutions you might use alongside it.
     
    Last edited: Dec 18, 2021
    one_one likes this.
  4. one_one

    one_one

    Joined:
    May 20, 2013
    Posts:
    621
    Thanks for the detailed reply, that sounds pretty good. So far I'm using a makeshift hand-rolled implementation which works out alright (for larger amounts of instantiation we're using DOTS anyway.) I especially like the async idea though and having everything in static methods also is a great bonus. So I'll stay tuned about this and hope the forum actually sends me a notification once there are new posts here :rolleyes:
     
  5. Gladyon

    Gladyon

    Joined:
    Sep 10, 2015
    Posts:
    389
    Nice project.

    A good thing to have with pools, is a way to detect when you haven't returned an object in it.
    In order to do that, I usually count the number of objects the pool provides, and the number of objects returned to the pool.
    At the end of the values must be the same, otherwise you know you forgot to return an object to the pool at some point.

    I usually don't like to keep a reference to the objects provided to the pool in order to check if they have been returned properly because that won't give me more information with .NET objects.
    But with a GameObjects only pool, you can also track the objects provided by the pool and when one is not returned you can tell its type, name and position, which is usually enough to know instantly which one is the culprit.
     
  6. M-Mahdi

    M-Mahdi

    Joined:
    May 7, 2021
    Posts:
    8
    You're welcome. I wish I could elaborate on some of the implementation details, but I don't think this thread would be the right place to do so. I know some parts of the system might seem magical at first glance, especially, since this is the first pooling solution providing such features. I will open source all parts of this system except for the editor tools on GitHub as a proof for my words and to let all those who are interested, try a lite version of this asset. Thanks for staying tuned.
     
    Last edited: Dec 18, 2021
    one_one likes this.
  7. M-Mahdi

    M-Mahdi

    Joined:
    May 7, 2021
    Posts:
    8
    Thanks. The feature you suggested although not built-in, it is somewhat covered in the analysis tool extending the system. This tool is provided as an editor tool and it works by recording the system's all and every action and generating statistical reports. You should be able to infer the information you want from these reports.
     
    Last edited: Dec 15, 2021
    one_one likes this.
  8. M-Mahdi

    M-Mahdi

    Joined:
    May 7, 2021
    Posts:
    8
    I have released the system's source on GitHub. Everyone can now test the system and see how it performs.
     
    Last edited: Nov 9, 2021
    one_one likes this.
  9. M-Mahdi

    M-Mahdi

    Joined:
    May 7, 2021
    Posts:
    8
    Good news for those who have been waiting to try out the full version of this asset. Since it has matured and it's ready for deployment, I will release it on the asset store as soon as I'm done with the preparation works. The system's core is open source and everyone can try it. I appreciate anyone sharing videos or pictures demonstrating the system in real projects. I may pick some of these and include them in the system's demo videos. Thanks in advance.
     
    one_one likes this.