This video is amazing. Lambda expressions always bamboozled me but apparently after a practicing coding daily and by your help I could finally understand it! Also creating the object pooler algorithm that suits your needs for your game looks really handy. Subscribed and liked!
Someone brought object pooling to my attention a couple of days ago, and I was kinda daunted by it, since I'm making a shmup with different projectile types that I would want pooled separately, and also parented in a certain way. This covered all of that. Thanks for making this!
Thanks so much! Especially for leaving the equivalent of lambdas for beginners. One of the best explained tutorials I've seen. I feel confident I can make an object pool myself.
Great video. Thank you for explaining in the beginning why you were "re-inventing the wheel". I agree that some better solutions aren't always needed for the scope/purpose of project.
Hey Brandon!!! Found out your channel a couple of weeks ago and after just your one video about the game dev i totally became a follower haha!! Really love all the content you are making! I just wanted to know isn't it tough making these kinds of tutorials while working for the competition time limit? If you don't mind can you suggest some time managing factors that you use cuz i am not a good time person and I really get this huge motivation from your videos to do my best!!! Thanks again for such an awesome tutorial!!
This is great, thank you. ☺ I've implemented it and added the ability to pass the number of default GameObjects to add to a new pool so that it can warm start. I need to add that this is much better than Unity's default implementation
I really appreciate you putting in the broken down version of what you did at 3:34, it helped me understand this part a lot better. Edit: If anyone is getting the log warning, make sure you actually changed it from "obj.name" to the new "goName" string when setting up the ReturnObjectToPool method.
Tried doing this twice but it didnt work but after seeing MY mistakes it started working and it was Beautiful lol I'm still confused a little by some of it but im sure ill figure it out. Thanks man its perfect for what I need it for.
At 5:49, why don't you use string.Replace() to remove the "(Clone)" part of the GO's name? Instead of doing string goName = obj.name.Substring(0,ojb.name.Length - 7); Do this: string goName = obj.name.Replace("(Clone)", string.Empty); (you can also make the "(Clone)" string a const property if you want to)
I was interested in understanding the concept of object pooling, so I searched for tutorials on CZcams. Your video on object pooling was the first one that appeared, and I watched it attentively to grasp the concept thoroughly. I clearly understood the process, and it made me wonder whether you mentioned that this method is quicker to set up compared to Unity's built-in approach. Consequently, I'm curious to know if you utilize the same object pooling technique in your own game development.
At 2:22 is there a reason you put that additional class outside the main class instead of making it inside and private? Also, is there an easy way to dynamically generate parent game object names for pooled objects, rather than using an enum? That way you could truly pool anything and have it sorted in the hierarchy automatically.
Great starter tutorial However I think as your game project grows and you will require more pools its better that these pools are organized in a dictionary than List. This will result in faster pool lookups.
Greetings! great video!!! Please tell me how you can implement stopping the movement of objects creating pools of objects! for example: there is a pool of objects, it creates an instance object that moves along the x axis, I need that when the player dies, the moving objects of the object pools stop, freeze in place, i.e. the game continued to run, but the objects were stopped by condition!
Hi, do you have a video on proving that saving memory and garbage collection improves the performance versus the standard? I know you mentioned that there is a pool utility that Unity provides. Are they the same type of performance in the video you're showing now?
I got it to work but it's still laggy like hell, have a tile system of 23x19x15 (but really only 23x19x7) as if I am on z 7 I only load 0-7 etc. But when I have 6 items (maximum) and 6 mosnters on every tile it's lagging
In the manager world of things. I noticed a pattern of creating a public variable called instance. I am not seeing it in your implementation. Perhaps it's not required, but what is your opinion on it? If it were to be used, how would you modify your object pool manager?
2:00 Are you saying that your implementation is faster than Unity's built-in solution or that yours is faster to set up? That's unclear to me. Nice video btw, enjoyed it!
Seems like the algorithm is finally picking up your channel! Object pools are a great staple of game dev. Though, did you know in unity 2021 they added one natively? UnityEngine.CoreModule.ObjectPool , not my favourite implementation but good to know its there.
@@sirzirkidevsalot My fix is when I disable them, I always return them to the storing folder because the way he make that one if you got two different parent GO with the same disabled childs, it might reactivate the wrong one.
*LIFESAVER COMMENT IF YOU GOT A BUG READ THIS!!!* 🗣🗣🗣🐞🐛🐞 (5 hours wasted by debugging) If you're returning an object to the pool in a OnCollision or OnTrigger then it can be called more times per one frame. That means the object will return more times per frame. That causes the object to be used even after being enabled. For example, bullets being randomly teleported back. To fix this simply make a bool and OnEnable set it to false then to true before returning, also the crucial part is actually checking if it's already returned, if yes then do 'return'. Return means that it won't run any code under.: private void OnTriggerEnter2D(Collider2D collision) { if (returned) // to prevent returning this object twice and damaging two or more enemies at once return; if (collision.CompareTag("Enemy")) { // logic } returned = true; ObjectPoolManager.ReturnObjectToPool(gameObject); }
same bug here. fixed it by checking if obj is already added to interactiveobjects. just add "if (!pool.Inactiveobjects.Contains(obj))" before "pool.Inactiveobjects.Add(obj);" in ReturnObjectToPool(Gameobject obj) method.
This video is amazing. Lambda expressions always bamboozled me but apparently after a practicing coding daily and by your help I could finally understand it!
Also creating the object pooler algorithm that suits your needs for your game looks really handy. Subscribed and liked!
Someone brought object pooling to my attention a couple of days ago, and I was kinda daunted by it, since I'm making a shmup with different projectile types that I would want pooled separately, and also parented in a certain way. This covered all of that. Thanks for making this!
Thanks so much! Especially for leaving the equivalent of lambdas for beginners. One of the best explained tutorials I've seen. I feel confident I can make an object pool myself.
Great video. Thank you for explaining in the beginning why you were "re-inventing the wheel". I agree that some better solutions aren't always needed for the scope/purpose of project.
Hey Brandon!!! Found out your channel a couple of weeks ago and after just your one video about the game dev i totally became a follower haha!! Really love all the content you are making! I just wanted to know isn't it tough making these kinds of tutorials while working for the competition time limit? If you don't mind can you suggest some time managing factors that you use cuz i am not a good time person and I really get this huge motivation from your videos to do my best!!! Thanks again for such an awesome tutorial!!
Found your channel not long ago and I love the content.
I dont understand why no one Play particle system, why do you instantiate ? It will cost more performance, i tested both
This is great, thank you. ☺ I've implemented it and added the ability to pass the number of default GameObjects to add to a new pool so that it can warm start. I need to add that this is much better than Unity's default implementation
this was a very informative tutorial! thank you so much for this!
I really appreciate you putting in the broken down version of what you did at 3:34, it helped me understand this part a lot better.
Edit: If anyone is getting the log warning, make sure you actually changed it from "obj.name" to the new "goName" string when setting up the ReturnObjectToPool method.
Haha. Exactly the error. I knew immediately what all my problems were made from when I read that.
Tried doing this twice but it didnt work but after seeing MY mistakes it started working and it was Beautiful lol I'm still confused a little by some of it but im sure ill figure it out. Thanks man its perfect for what I need it for.
At 5:49, why don't you use string.Replace() to remove the "(Clone)" part of the GO's name?
Instead of doing
string goName = obj.name.Substring(0,ojb.name.Length - 7);
Do this:
string goName = obj.name.Replace("(Clone)", string.Empty);
(you can also make the "(Clone)" string a const property if you want to)
You can also use string Contain to check
I was interested in understanding the concept of object pooling, so I searched for tutorials on CZcams. Your video on object pooling was the first one that appeared, and I watched it attentively to grasp the concept thoroughly. I clearly understood the process, and it made me wonder whether you mentioned that this method is quicker to set up compared to Unity's built-in approach. Consequently, I'm curious to know if you utilize the same object pooling technique in your own game development.
Cool video! Thanks for tutorial
Would it not be more efficent to use a Dictionary?
At 2:22 is there a reason you put that additional class outside the main class instead of making it inside and private?
Also, is there an easy way to dynamically generate parent game object names for pooled objects, rather than using an enum?
That way you could truly pool anything and have it sorted in the hierarchy automatically.
Whoah, thank you so much!
Great tutorial! Is there any way to do the same thing by using built in object pooling method?
Could u show performance dif between instantiate and object pooling
Great starter tutorial However I think as your game project grows and you will require more pools its better that these pools are organized in a dictionary than List. This will result in faster pool lookups.
This is so awesome!!
Thank you! :D
How would you addapt it to net code i wonder
Greetings! great video!!! Please tell me how you can implement stopping the movement of objects creating pools of objects! for example: there is a pool of objects, it creates an instance object that moves along the x axis, I need that when the player dies, the moving objects of the object pools stop, freeze in place, i.e. the game continued to run, but the objects were stopped by condition!
Hi, do you have a video on proving that saving memory and garbage collection improves the performance versus the standard? I know you mentioned that there is a pool utility that Unity provides. Are they the same type of performance in the video you're showing now?
HUGE THANKS!!!!
Underrated asf
I am running into an issue with this solution where it will not work when moving to a different scene, has anyone else experienced a similar issue?
I got it to work but it's still laggy like hell, have a tile system of 23x19x15 (but really only 23x19x7) as if I am on z 7 I only load 0-7 etc.
But when I have 6 items (maximum) and 6 mosnters on every tile it's lagging
In the manager world of things. I noticed a pattern of creating a public variable called instance. I am not seeing it in your implementation. Perhaps it's not required, but what is your opinion on it? If it were to be used, how would you modify your object pool manager?
The functions are static so just ObjectPoolManager.SpawnObject(...). So making a singleton is useless.
2:00 Are you saying that your implementation is faster than Unity's built-in solution or that yours is faster to set up? That's unclear to me.
Nice video btw, enjoyed it!
Faster to setup
only some of my objects get the (clone) why?
Cool idea to have object pools created at runtime. ✌️ VERY modular and generic ✌️✌️✌️
Seems like the algorithm is finally picking up your channel! Object pools are a great staple of game dev. Though, did you know in unity 2021 they added one natively? UnityEngine.CoreModule.ObjectPool , not my favourite implementation but good to know its there.
Good enough for a CZcams free tutorial.
It's a starting point, but I wouldn't recommend using this for production.
so what would you recommend ?
Im having problems with this, sometimes it works but sometimes it just clones the prefab and doesnt reuse it
Probably the same problem I've encountered, but did found a way to fix it.
What was the fix you made?@@FyresGames
@@sirzirkidevsalot My fix is when I disable them, I always return them to the storing folder because the way he make that one if you got two different parent GO with the same disabled childs, it might reactivate the wrong one.
*LIFESAVER COMMENT IF YOU GOT A BUG READ THIS!!!* 🗣🗣🗣🐞🐛🐞 (5 hours wasted by debugging)
If you're returning an object to the pool in a OnCollision or OnTrigger then it can be called more times per one frame. That means the object will return more times per frame. That causes the object to be used even after being enabled. For example, bullets being randomly teleported back.
To fix this simply make a bool and OnEnable set it to false then to true before returning, also the crucial part is actually checking if it's already returned, if yes then do 'return'. Return means that it won't run any code under.:
private void OnTriggerEnter2D(Collider2D collision)
{
if (returned) // to prevent returning this object twice and damaging two or more enemies at once
return;
if (collision.CompareTag("Enemy"))
{
// logic
}
returned = true;
ObjectPoolManager.ReturnObjectToPool(gameObject);
}
same bug here. fixed it by checking if obj is already added to interactiveobjects. just add "if (!pool.Inactiveobjects.Contains(obj))" before "pool.Inactiveobjects.Add(obj);" in ReturnObjectToPool(Gameobject obj) method.
First
Okay, I am going to meet you when I come to Canada for my master's degree. My name is Ajay, and I am an Indian game developer.
Why would you type so fast. It makes everything unclear and hard to catch up
thanksss
First