Implement Object pooling in your Unity Game

Sdílet
Vložit
  • čas přidán 17. 07. 2024
  • In this video we will implement object pooling in a practical way by pooling the projectiles fired by the player's weapon. We will also expose and overcome common problems that arise when implement pooling in a real game. #unity #unitytips #gamedev
    Useful Links:
    -To Pool or not To Pool, that is the question : • To Pool or Not To Pool...
    - Object Pooling Detailed Guide: thegamedev.guru/unity-cpu-per...
    - Unity Asset Store: assetstore.unity.com/?aid=110...
    - Roguelite Tutorials: • Soap Tutorials (Make a...
    Subscribe to the channel for more tips!
    www.youtube.com/@obviousgame/...
    --------------------------------------------------------------------
    Chapters:
    0:00 Intro
    0:23 Different pooling systems
    0:39 Profiling
    1:18 Initial Weapon code
    1:41 Initialize the pool
    2:57 Using the pool
    4:05 Common Problems
    5:36 Testing & profiling
    5:54 Linq Garbage
    6:29 Results
    6:53 Outro
    --------------------------------------------------------------------
    - Discord : / discord
    - Twitter : / obvious_game
    - Asset Store Page : assetstore.unity.com/packages...
  • Hry

Komentáře • 8

  • @joaogabriellimamoraes4087
    @joaogabriellimamoraes4087 Před 9 měsíci +1

    best explanation of how to use the feature so far. Thanks!

  • @Nearueki
    @Nearueki Před 10 měsíci +1

    good explanation man, thanks very much

  • @deadadam666
    @deadadam666 Před 9 měsíci +1

    v nice , keep it up

  • @risingforce9648
    @risingforce9648 Před 6 měsíci

    how can I deleate and allwasy keep 10 clones? I mean I put this :
    private void Awake()
    {
    _pool = new ObjectPool(CreateProjectile , null ,OnPutBackInPool,defaultCapacity:10);
    }
    this is the method to control the maximum size of the pool right? I put 10... the problem is I see in my hierachy an accumulative objects (clones) by 10... the first time I shoot not matter , the pool deleates everything, the problem is when I pass 10, they are increaseing the number in +10...adn at the end of the day I ve a lot of Clones in the hierachy...some are deleated of course...but never keeps 10 !

    • @obviousgame
      @obviousgame  Před 6 měsíci

      Its not the max size of the pool, its the initial pool capacity. That means, when the pool is created it will allocated space for 10 objects. If you spawn more, it will increase the capacity of the pool. If you know you are going to have a certain amount of bullets at the same time, put that number as the default capacity :).

    • @risingforce9648
      @risingforce9648 Před 6 měsíci

      @@obviousgame I followed your tutorial , I ve created a similar class, I meant I also have a Class for weapon, but it is strange for me, when I put 10 to allocated only ten objects, always add 10 more to the first 10...probably I also reduce the time of lifeTime but it is the same for me..I am missaunderstood ? thaks.

    • @obviousgame
      @obviousgame  Před 6 měsíci

      @@risingforce9648 If you come on the discord channel and post some screenshots maybe I can help you better ;)