Object Pooling in Unity! Easy Tutorial!!

Поділитися
Вставка
  • Опубліковано 29 лис 2024

КОМЕНТАРІ • 12

  • @Tenetri
    @Tenetri 10 місяців тому +1

    really cool explanation, very inspiring! Thank you!

  • @ryanwinchy
    @ryanwinchy 10 місяців тому

    So useful thanks so much! Hadn't seen this before. So well explained.
    Would love to see more tutorials :)

    • @GarnetKane
      @GarnetKane  9 місяців тому

      Appreciate it! More tutorials coming :)

  • @muhammadzubairirshad6724
    @muhammadzubairirshad6724 3 місяці тому +1

    Amazing Explanation

    • @GarnetKane
      @GarnetKane  3 місяці тому

      Appreciate it! Glad it was helpful :)

  • @adamodimattia
    @adamodimattia 6 місяців тому +2

    By now, there is already Unity built-in object pooling api :)

  • @urpwnned
    @urpwnned 9 місяців тому +3

    Im having a really hard time understanding how dictionaries work :(

    • @GarnetKane
      @GarnetKane  8 місяців тому +5

      Hey there! Apologies on the delay in my response - hopefully this explanation helps.
      A Dictionary is set up which includes 2 properties, a KEY and a VALUE - think of the KEY as almost like a username, and the value is the account that it belongs to. When you put the Key into the dictionary, if it contains an entry (as in the account exists somewhere), then it will return it.
      So setup would be like:
      Dictionary myDictionary = new Dictionary();
      in this case, our KEY is the string and our VALUE is the integer.
      Now think of a list setup, you would add to a dictionary similar to how you would a list, but this time you need the identifier (key) and you need the value. So initialising the dictionary would be something like:
      myDictionary.Add("Garnet", 100);
      so by doing this, we now have a unique entry for something called Garnet that has a value of 100.
      When we want to look through the dictionary to find a value, we can search by doing something like:
      myDictionary["Garnet"] -> but this is ASSUMING we know that there's a key for Garnet, a more common approach would to null check it
      if(myDictionary.ContainsKey("Garnet")){
      print(myDictionary["Garnet"]);
      }
      It's definitely a lot to wrap your head around, but I hope this helped in some way with it!

  • @msmigs1173
    @msmigs1173 Місяць тому

    I get the concept but literally zero idea how the code works, but my fps has never been so good.

  • @tr25ny
    @tr25ny 7 місяців тому +1

    For some reason when the pool is full and all of them are in use and then starts instantiating new objects, it then skips generating every 2nd object from then on.

    • @ENRI_465
      @ENRI_465 4 місяці тому +1

      If anyone else has this problem changing the last line of the *EnqueueNewInstance()* method fixes it:
      Instead of
      return newInstance;
      write this
      return (T)poolDictionary[key].Dequeue();

  • @TongThachPham
    @TongThachPham 3 місяці тому

    Why use queue and not stack?