Level up your code with game programming design patterns: Object pool | Tutorial

preview_player
Показать описание
In this video, you’ll learn more about object pooling, how it can provide performance optimization by reducing the processing power required of the CPU to run repetitive create and destroy calls, and how to use it in your Unity projects.

Timestamps:
[0:00] Intro
[0:54] Overview of code
[1:26] Variables in the example script
[3:04] Object pool constructor overview
[4:55] Overview of the projectile script

#unity #unity3d #gameprogramming #unitygamedev #gamedev #gamedesign
Рекомендации по теме
Комментарии
Автор

Thank You for making this Programing Patterns (for videogames) series.

alec_almartson
Автор

Wonderful new API. Thanks to the devs for adding this.

skanda
Автор

This is great. I've been using my own version of this for couple of years and it's almost the same as this. I was tired of complex MonoBehaviour solutions and I did simple but flexible option with func delegate with Get/Release to handle it basically from anywhere in your code. This allows you to have your own script, as you already have (probably with Instantiate), just reference to the prefab and viola, spawn it with Pool instead.

markoaleric
Автор

I've been using this for quite sometime now great feature

enamulislamjisan
Автор

I was actually about to program my own, thank you xd

sactecnos
Автор

This is kinda cool, probably works better then when i coded it myself 😂

HuskiGames
Автор

Been using this for a good while. Though I believe the last I've used it, I wish the feature calling 'clear' on the pool collection to just auto releases them all back to the pool than to destroy.

hyperlenz
Автор

Is there a cleaner way to return the Projectile to the pool? Given the provided setup, Projectile would throw an error outside of a pooled context. There's also no indicator for those using the Projectile class that its ObjectPool variable must be set prior to use.

Maybe a better solution would be to define a "OnDeactivate" event on the Projectile, which is called at the end of that coroutine. The CreateProjectile method would then subscribe to the event in a way where Release is called when it triggers. Now the Gun class completely manages the lifetime of the projectile, and the projectile is free to be used in any context.

SBroproductions
Автор

when do you use the serialize field and what is it used for?
also the pooling looks very helpful thank you for that

anim_atix
Автор

Hard coded dependency here, unfortunately. Projectile should not ever know about the object pool. Instead a very simple way to add an OnCompleted or OnFinished event to the projectile and assign any custom method to it there from the code where the projectile is instantiated. This way it can be kept clean. Though the ObjectPool API is a great to have tool. Thank you.

twinjuke
Автор

Where is the interface keyword in the IObjectPool declaration? Was it a mistake or am I missing something?

anuraagchandra
Автор

Hmm, I would have thought it should be the object's responsibility to activate or deactivate itself. Calling "SetActive()" etc inside the gun breaks separation of concerns I think. The bullet I'd expect to have an interface to implement these per object?

Octamed
Автор

You didn't really explain why we would do this. Is there some savings on transfer of information?

TinyGiraffes
Автор

Do we need to import some sort of pakage from asset store to use Object Pool APi ?

TheJangoo
Автор

i do not like the fact that the bulletObject calls the GetComponent API in fixedupdate. it's a very bad practice and will lead to issues. instead that should be changed to have a cached rigidbody.

BusEyes
Автор

These OOP patterns are useless to create a large open-world multiplayer game with C#, because the performance will always be much slower than DOTS or C++

containedhurricane
Автор

the worst IDE that can exist, if I mean visual, both the code and the community; You have to see how many complaints there are about this garbage everywhere and the fact is that Bill's sick person selling his Win 11 makes it slower to program on 5-year-old computers so they buy the new computers because the old ones don't have any use for it. win 11; The code does not auto complete, Unity seems lost, lag and a white screen in visual. bad unity garbage.

minimalpoint
Автор

Your CEO sucks. Get his greedy little hands out of others bank accounts and make him grow up.

bRuHIsHere.