OBJECT POOLING in Unity

Поділитися
Вставка
  • Опубліковано 22 січ 2025

КОМЕНТАРІ • 670

  • @sadiqabbaszade4789
    @sadiqabbaszade4789 4 роки тому +420

    You are gone but the content you left behind will forever help game developers like myself.

    • @xtragamez7195
      @xtragamez7195 3 роки тому +1

      @Islam Abukoush wait WHAT

    • @krysidian
      @krysidian 3 роки тому +2

      @Islam Abukoush You really played with my emotions like that. Damn.

    • @krissloo143
      @krissloo143 3 роки тому

      @Islam Abukoush Bastard :,)

    • @ShahbazGames
      @ShahbazGames 3 роки тому

      True

    • @VyLoneReaz
      @VyLoneReaz 3 роки тому

      Is he dead?

  • @FoxApo
    @FoxApo 3 роки тому +76

    For those who are new to this topic. Instead of creating Interface with extra method, you don't have to do this. You can just rename Start method in Cube class to "OnEnable". It's a method which is called each time you SetActive(true) on Game Object. Do not overcomplicate things and try to use built in methods which are part of MonoBehaviour, sometimes things can be done easier than you think. OnEnable method is basic life-cycle function within MonoBehaviour class and it's a very common thing to use, so don't forget about this :)

    • @3d_toys
      @3d_toys 2 роки тому +2

      Well didn't work for me. But I should mention I'm just a beginner and I barely understood all of Brackey's pipline in this video

    • @pauljansen2377
      @pauljansen2377 Рік тому

      @@3d_toys Rly ? because that's exactly what I thought to do when I watched this video, However I didn't test it so maybe there is something that i'm missing

    • @Laranthir
      @Laranthir Рік тому

      I wonder if this has actually worked

    • @speedrhythmics1839
      @speedrhythmics1839 17 днів тому

      I'm not entirely sure if I am missing something, but I think in Brackeys' example using an interface was the best choice because his cube's functionality doesn't involve having to disable it at any point, rendering (pun intended) constantly disabling and re-enabling his cubes redundant. That being said, I think your suggestion is perfectly fine otherwise; it is just unsuited for Brackeys' needs in the video.

  • @sykoo
    @sykoo 7 років тому +498

    Nice to see that optimization is being heavily lifted upfront for indie devs!
    Keep it up.

    • @ryanrichardson4056
      @ryanrichardson4056 5 років тому +9

      Sykoo but i thought you were the “screw the performance!” guy xD

    • @andrewherrera7735
      @andrewherrera7735 4 роки тому

      @@ryanrichardson4056 I used to then I figured out you could have 3x the objects for the same performance.

    • @lightningcode1136
      @lightningcode1136 4 роки тому +1

      I am a dev

  • @Fangh44
    @Fangh44 5 років тому +122

    Thank you for this videos with 3 subjects :
    - Pooling
    - Singleton
    - Interface.
    That was dense and rich ! thank you !

    • @IluXa4000
      @IluXa4000 4 роки тому +1

      Using singleton is bad practice actually. I can understand that brackeys did that for beginners, but anyway. You can always create a [SerializedField] in CubeSpawner and put your ObjectPooler into that field from the inspector.

    • @giovanni.piedimonte
      @giovanni.piedimonte 4 роки тому +8

      @@IluXa4000 Singleton is a base pattern, why is a bad practice? Can you link a resource can prove your affermation?

    • @tomtomkowski7653
      @tomtomkowski7653 3 роки тому +1

      @@IluXa4000 Like what? From when singletons are bad practice? Please explain and give us a resource of this revelation.
      Singletons are totally normal and fine and used often. As often as you have some unique class that should be instantiated once and all other scripts have access to it.

    • @hhcdghjjgsdrt235
      @hhcdghjjgsdrt235 3 роки тому

      but i think the interface was not necessary, I did this with a normal public method without creating any interface.

    • @ultmatepotato
      @ultmatepotato 2 роки тому

      @@giovanni.piedimonte lmao hegot ratiodin a youtube comment section

  • @nocturne6320
    @nocturne6320 3 роки тому +126

    I know this is a pretty old tutorial, but just in case anyone is still interested after all the years, here are a few notes about this.
    1. It would be better to turn this into a normal static class instead of a MonoBehaviour, better for both performance (MonoBehaviour adds unnecessary bloat) and ease of access (since its static theres no need for singletons)
    2. Instead of just logging a warning to console when a wrong tag is inserted, throw an exception. ALWAYS throw an exception when something goes wrong, don't just silently return, or just log into console. Make the code scream on top of its lungs that something is wrong.
    3. The initialization of the queues should be lazy, that means don't just instantiate all the objects at load, instead instantiate them when they are requested, or when some method, like "AllocateObjectPool", or something like that is called. This way youre making sure the objects are allocated only once they are actually needed and don't occupy memory when they won't be used for another few minutes.

    • @bicuswang5149
      @bicuswang5149 3 роки тому

      Can you be specific about how to turn it into static class?
      and with the singleton Instance thingy does it not mean that I can also access its variables?

    • @nocturne6320
      @nocturne6320 3 роки тому +12

      @@bicuswang5149 Just remove its MonoBehaviour inheritance and make the class itself static. Make all the variables and methods static, remove the SharedInstance field as its no longer needed and you have it.
      After that you just need another way of automatically calling the Awake method for the class to initialize properly.
      - You can do that by either using a RuntimeIntializeOnLoadMethod attribute on the Awake method, which will automatically invoke the method after the first scene is loaded.
      - Or you can use a static class constructor, which is a class constructor with no parameters that gets automatically called once as early as possible.
      After that you can use the class like before, just instead of ObjectPooler.SharedInstance.GetPooledObject you just call ObjectPooler.GetPooledObject.
      Static classes are a better way of doing Singleton MonoBehaviours that don't need any of the MonoBehaviour features (like the update methods, or access to the parent gameobject, etc.) as without the extra MonoBehaviour stuff they are more lightweight and easier to use/understand how to use them.

    • @kuroakevizago
      @kuroakevizago 3 роки тому

      ​@@nocturne6320 If we're not using the Mono behaviour class, than how are we going to add the list of Item we need to pool from the Inspector ?

    • @kuroakevizago
      @kuroakevizago 3 роки тому

      So what you mean in the point 3 is that we start Instatiate the Game Object and put it on the pool when they really are needed(requested) ?

    • @nocturne6320
      @nocturne6320 3 роки тому +4

      @@kuroakevizago You could have another class (monobehaviour) with just a list of items to pool that you could pull the items from. As they are needed only for initialization you could destroy that script afterwards.
      Or add some method for it into the class, which should be there anyway as it could be useful to request a new object to be pooled, or request an item that is already pooled to have a bigger pool size.

  • @Flemdragon
    @Flemdragon 6 років тому +5

    I love how I watch the unity videos and I’m still confused. Then I come to your channel and I understand. Thanks for this!!!

  • @orlandoalmario
    @orlandoalmario 7 років тому +2

    I did not expect to learn so much from a single 17 minute video, this is so much more than just object pooling, thank you for doing such an amazing job!

  • @ChrisisAwesome1
    @ChrisisAwesome1 7 років тому +44

    Brackeys, you have a habit of uploading what I need right when I need it. Did it with tilemaps and now this. Keep it up! :D

  • @KandyMan90
    @KandyMan90 7 років тому +70

    Best way to get rid of the get component call would have been to rename start to on enable. No need for the interface

  • @wulumgames
    @wulumgames 4 роки тому +2

    This tutorial offers exactly the information that I needed. It's not a beginner's subject, but it's a good one to have it cover on the internet. Thanks, man.

  • @LMHPOLY
    @LMHPOLY 7 років тому

    Just two days ago I read about Object Pooling in the book ( about Unity Game Optimization). And now you made a tutorial about that, so huge thanks to you!

  • @Maggiethegsd
    @Maggiethegsd 4 роки тому +2

    A full series or even a video on optimizing your game would be really helpful!

  • @adammankai5661
    @adammankai5661 7 років тому +4

    Your tutorials are THE BEST they helped me a lot since I started using Unity. So thank you

  • @BimzyDev
    @BimzyDev 4 роки тому +3

    Great tutorial. I love how structured your tutorials are, and easy to follow along!

  • @rishabhbhatt8270
    @rishabhbhatt8270 4 роки тому +1

    I can't believe I found this video now. I wanted to implement multiple spawning objects in my game for the GMTK 2020 game jam but I wasn't able to make it efficient. As a result, my game lagged horribly on many devices and got a poor rating ;-( But this video was all that I needed. Thanks Brackeys for this excellent in depth tutorial, will use this to improve my game.

  • @pedrosousa6576
    @pedrosousa6576 7 років тому

    I was actually looking into object pooling, this is great. Thanks brackeys! Keep making these gems.

  • @CoReeYe
    @CoReeYe 6 років тому +22

    10:43 Pool with tag doesn't exorcist :')

  • @FreddyNewton
    @FreddyNewton 4 роки тому

    After 2 years - skillshare link works! Love too support u @brackeys

  • @MadpolygonDEV
    @MadpolygonDEV Рік тому +2

    To anyone new seeing this. Instead of using a string as tag use a int as tag. Strings are unnecessary

  • @Opcode_
    @Opcode_ 7 років тому +1

    This is some really cool OOP stuff, implemented in Unity. I never even thought about optimizing my Instantiates this way

  • @instasquid
    @instasquid 5 років тому

    Just want to say thanks for this. I really appreciate your tutorials. So useful, no mucking around. Great level of explanation of the component parts. Keep up the good work!

  • @fishbreath8206
    @fishbreath8206 4 роки тому +11

    Brackeys: calls an object queue a pool
    Unity: “From now on you’re all pools”

  • @gadgetboyplaysmc
    @gadgetboyplaysmc 7 років тому

    I'm always like... What would I ever do without Brackeys man?

  • @xavierh8902
    @xavierh8902 7 років тому +214

    Brackeys = Best Unity Tutorials
    Edit: Thanks for the like Brackeys!!

    • @Cognitionz
      @Cognitionz 7 років тому +9

      Seriously. I'm amazed how he breaks complex things down and how well he describes each feature.

    • @simonmadception3980
      @simonmadception3980 7 років тому +23

      that's not gonna work, try:
      public string Brackeys = "Best Unity Tutorials";

    • @OverAndOverAndOver
      @OverAndOverAndOver 7 років тому +1

      Simon Madception love it XD

    • @trifalgarh
      @trifalgarh 6 років тому +6

      But for better performance maybe you could go for this:
      public readonly string Brackeys = "Best Unity Tutorials";

    • @risingredstone5949
      @risingredstone5949 6 років тому

      It should be [ReadOnly] not readonly

  • @svetlinsvilenov8739
    @svetlinsvilenov8739 7 років тому

    It's very nice to see a good optimization video. Please do more videos like this, where you make easy to understand examples of the use of different data structures.
    Keep up the good work :)

  • @inderjeet2992
    @inderjeet2992 7 років тому

    Really very helpful. Thankyou so much brackeys for tutorials on difficult topics in an easy way.

  • @VariableGoose
    @VariableGoose 7 років тому +41

    Plz make a Shader series

  • @AMANKUMAR-fc1yp
    @AMANKUMAR-fc1yp 7 років тому

    Brackeys, you are the best! believe me i was gonna ask in comments for object polling !

  • @JuniorDjjrMixMods
    @JuniorDjjrMixMods 4 роки тому +1

    My considerations:
    Use OnEnable() instead of creating a new function to call it when enabling. The problem is, if the object is already enabled (it's already being used), the OnEnable will be not called. You have a option to don't reuse if it's already being used (some games are created like this), so it's expected that your object will be disabled after using and you always validate if the object returned if valid to enable.
    Use enum instead of string on tags. Faster, and this way you don't need to check if tag exist, after all, if you try a enum that doesn't exist, the compiler itself will tell you.
    Instantiate in Awake instead of Start, to make it possible other scripts call it during Start (when game starts).
    Before instancing, create a game object named "Pools Objects", and instantiate as a child. So you avoid seeing a thousand objects on your hierarchy view.

  • @Gundalian
    @Gundalian 6 років тому +4

    A quick note on the singleton usage in the video. The reason you generally use singletons is when you want to have global access to a specific instance of the class without having any copies of it. Just for the sake of this video, I think it's a bit redundant since there's only one system referencing it (cube spawner) + you assign your own local variable to that singleton. I would instead have simply instantiated a new version of the Object Pooler inside the Spawner, or had a dependency injection on your local variable :)

  • @Nobody-my6ye
    @Nobody-my6ye 5 років тому

    I feel like I did something awesome but I don't still get it haha. I have to watch this video over and over again! Thanks a lot, Brackeys. Saludos desde Colombia.

  • @JustPlainRob
    @JustPlainRob 4 роки тому +1

    Holy crap, multiple inheritance! Brackeys going deep on this one.

  • @nolanrux7866
    @nolanrux7866 3 роки тому +1

    These tutorials make it so simple to understand!
    You're the man!

  • @crowkae
    @crowkae 7 років тому

    this is what i've been waiting for such a long time

  • @PaulysGarage
    @PaulysGarage 4 роки тому

    Thanks for this. I am using object spawning with images and a particle system. It saved my game.

  • @kaanozkordag
    @kaanozkordag 4 роки тому

    Great tutorial of singleton, interface and pooling all together.

  • @milkstorm4818
    @milkstorm4818 4 роки тому +13

    11:23 don’t mind just a reminder for tommorow

    • @trashcaster
      @trashcaster 4 роки тому

      Ya, that region bit it the most useful thing in the video. Don't get me wrong, object pooling is great. But that applies to less than the regions stuff would, I would think.

  • @cammasgv
    @cammasgv 7 років тому +1

    who ever hates this video hates games i love this channel

  • @thepithief3700
    @thepithief3700 7 років тому

    Love your visible representation of an object pool :)

  • @denny7477
    @denny7477 7 років тому

    I LOVE YOU ! Object pooling is just what I needed !!

  • @danielfloresg
    @danielfloresg 3 роки тому +1

    2:54 Brackeys: and the third one with... well, something.
    Pentagons: Am I a joke to you

  • @nikhilagrawal2423
    @nikhilagrawal2423 7 років тому

    awesome video bro
    I was searching for some pooling script for my new game and your video found out to be very useful to me.

  • @BeerfootBandit
    @BeerfootBandit 7 років тому

    Glad brackeys did an object pooling tut

  • @liveisamelody9413
    @liveisamelody9413 6 років тому

    you made my Day! i was working on a agar.io clone, and run into the problem that everything got laggy because of all these objects in the scene. keep up these amazing tutorials, god bless you.

  • @brycejohnson1480
    @brycejohnson1480 6 років тому

    I've been a full stack Developer for two years but now I finally understand interfaces

  • @GameDevBox
    @GameDevBox 2 роки тому

    the best 17 min of my life :D

  • @jesse8606
    @jesse8606 7 років тому +15

    Can you make a tutorial over how to make a car driving with wheel Colliders? Love your videos btw

  • @JavierMorales-qo4ok
    @JavierMorales-qo4ok 4 роки тому

    For some reason, without creating the interface, (only with the start method) it worked, and i've created the exactly like you

  • @pavelkozyar9121
    @pavelkozyar9121 4 роки тому +2

    i didn't get how can i return object in queue from another script (example when enemy die i want to return him for later usage)

  • @holdenflames
    @holdenflames 7 років тому +1

    This is a list of dictionary's :-D Very hard to find a clear example of one but with the added bonus of queues this will really help me thanks :-D

  • @diliupg
    @diliupg 4 роки тому

    Instead of a cube if water particles were used, you could have actually spawned a swimming pool! yay! :-D This is the best tute on object pooling!

  • @TheOriginalDarkGlitch
    @TheOriginalDarkGlitch 7 років тому

    Been waiting to see how you'd implement a pooler. Nice tutorial. Poolers are a must have for any game that uses tons of objects that are for the most part, the same, such as Danmaku[bullet hell] games.

  • @selen00b95
    @selen00b95 6 років тому

    You can also use a List, and in the spawn method, check for an available item instead of use the first one in the Queue. It works better with this approach for my rythm game.
    Good job bro', it was an awesome video as always :)

  • @spargroup7516
    @spargroup7516 7 років тому +20

    A quick thought: This technique may be used for creating a pool of 3-4 (or as many as you want) muzzle flashes in a shooter game. It can then be called randomly to make the game look realistic with muzzle flash variations along with maintaining the speed of the game...Please pin this if you think this might prove to be a good idea! Also, thanks Brackeys, you have the best tutorials for Unity on the internet!

    • @aronlinde1723
      @aronlinde1723 7 років тому +2

      SPAR Group I was thinking about using it for projectiles. They are one of the most expensive and common things to spawn and you can predict the pool per weapon (either max magazine size or by Max range / velocity * Rounds per second). But I like the idea for particle based objects since they are expensive.

    • @ravenofcode8072
      @ravenofcode8072 5 років тому

      @SPAR Group that's not what object pooling is for 😂, muzzle flashes don't need to be pooled as they only have 1 per gun, not an unknown amount

  • @Sandro1155
    @Sandro1155 6 років тому

    Your Videos are so good, that this in fact is a reason for me to keep using Unity and not Unreal Engine ;)

  • @jackyboy3025
    @jackyboy3025 7 років тому

    yay, i have been waiting for this for a while!

  • @MrProthall
    @MrProthall 7 років тому

    Can I just... Can I just say how damn great a teacher you are? Guess I'll do it: You're a damn great teacher.

  • @frogstair
    @frogstair 7 років тому +18

    We want a shader tutorial!

  • @reznal
    @reznal 6 років тому

    Instead of using the singleton, you can just make the Dictionary, get/return methods static methods/variables. Also in most cases, OnEnabled would be fine instead of using an interface. Besides that, great tutorial as always :D

  • @n.aclasheryt4802
    @n.aclasheryt4802 7 років тому +1

    I really needed it 4 days ago, but okay i will implement it now

  • @fahadmirza8497
    @fahadmirza8497 6 років тому

    always great tutorials by brackkeys ....like you guy !!

  • @knikgamedevstudio1060
    @knikgamedevstudio1060 5 років тому

    Best example so far, thank you

  • @rederjoubert
    @rederjoubert 7 років тому

    Thank you very much Brackeys! I used the object pooling for my enemies since I don't have to destroy my enemies, I can just disable the enemies and then reuse the enemies again. This has helped me a lot. Well, a lot of your videos have helped me. If you can, please have a look at my channel, I am currently working on a game, would love your thoughts and criticism, thank you for your time. Please keep on making amazing videos :)

  • @fulldivegames667
    @fulldivegames667 2 роки тому

    I'm not gonna lie, I understood damn near none of that but I'm in a game jam so idc thank you king.

  • @bharathkrish6743
    @bharathkrish6743 7 років тому

    Hi, bro excellent explanation about object pooling.. I ll never see any rummy game development based video tutorials on UA-cam.. If you start the series.. Surely it will be unique in UA-cam.. I can also learn from you a lot..:)

  • @MarcAnthorn
    @MarcAnthorn 6 місяців тому

    Wonderful tutorial! Thanks a lot🎉

  • @renynzea
    @renynzea 6 років тому

    The only thing I would suggest is setting the size of the pool when it is initialized, since you know the size at creation. Otherwise you end up with the internal array that represents the queue getting copied more than once as you enqueue objects.

  • @solomonlyons10
    @solomonlyons10 7 років тому +47

    Can you make a series on game security. Like locking leaderboards or way to minimize cheating?

    • @solomonlyons10
      @solomonlyons10 7 років тому +1

      Thanks to the both of you. This really helps!

    • @solomonlyons10
      @solomonlyons10 7 років тому +1

      jeka7676 sweet dude. Yea, my game is a single player but with a global leaderboards. Well, I'm trying to set the leaderboard now haha. Thx again!

    • @leonidus101
      @leonidus101 7 років тому

      I doubt it hard that he will do such an extensive series.. I asked him in an email months ago how are backends in some round based mobile games implemented and if he can recommend any providers - no answer. It is almost all about back end server programming and session syncing - easier for round based games and harder for real time action. There are some BaaS providers, like GameSpark, that decrease the steep learning curve and have extensive documentation and tutorial. But if you use that providers and have a f2p game and you have what I call "sudden success" - means a lot more that 100 000 monthly active users and the in-app-purchases are not generating capital, you are f*cked with a huge bill on the table.

    • @kidpog3d101
      @kidpog3d101 6 років тому +2

      1. have the most important calculations and data server sided.
      2. everything that is in the ram of a client can be hacked easily
      3. keep up to date with hacks for your game and fix them ?

    • @MasterTeeee
      @MasterTeeee 5 років тому +3

      @Evgeny Gutman "Also the client needs to check if the data is the same as the server's" - Biggest problem is that I can reverse the game (not that that's necessarily a doddle), and remove the call to the server entirely.
      Rule #1 for Security: Anything that is on the client (on the end-users device) is exploitable. Period.

  • @DavidZobristGames
    @DavidZobristGames 7 років тому

    object pooling, singleton and interfaces in one video nice one

  • @mkaali
    @mkaali 5 років тому +1

    So how do I put an object back to pool and reset it? I have moving targets which I used to Instantiate and Destroy. Now when using this system, when the pooler loops around and spawns the oldest object, it remains where it was left in its previous lifetime instead of the start position where I first spawn it. I assume all of its properties are carried over. So how can I reset it back to its prefab values?

  • @RobertPlayz231
    @RobertPlayz231 7 років тому

    Awesome video :D btw it's my birthday today and I would love a Happy Birthday from you :D

  • @smallguillotine6750
    @smallguillotine6750 6 років тому +3

    Really great tutorial. Loved the implementation of interfaces, learnt how to use them and sorta made a damage interface too for things that can take damage. Still can't figure out how to not use .GetComponent for the interfaces though.

  • @Heisenberg-xc8ub
    @Heisenberg-xc8ub 6 років тому

    Interfaces are awesome!

  • @mercurial6480
    @mercurial6480 7 років тому

    finally some optimization tutorials

  • @ReenoMoon
    @ReenoMoon 5 років тому +1

    11:00 how can i make the object skip in line if it is inactive in front of the active objects used in the scene?

  • @dspartan007
    @dspartan007 4 роки тому

    Just what i was searching for

  • @psinjo
    @psinjo 5 років тому

    Thank you so much for this, I found it very detailed and very informative without being overly complicated.
    Do you think you would be willing to make a tutorial on different forms of inheritance?
    Why did you use an interface instead of a class?
    When should you use one over the other, why would you not derive from monobehaviour?
    ... etc etc. I would be really interested in seeing the inheritance system broken down. Thank you again for the info!

  • @TheCrXe
    @TheCrXe 6 років тому

    this is the best tutorial ever made!

  • @ninjixfatality
    @ninjixfatality 6 років тому

    This is amazing for my spawner instead of destroying an object which can make the object null!!

  • @MaeveFirstborn
    @MaeveFirstborn 7 років тому

    Your content is fantastic.

  • @cargorunnerUK
    @cargorunnerUK 3 роки тому

    Really interesting video - will certainly try and use some of this code.

  • @engineoilgames3041
    @engineoilgames3041 7 років тому

    Awesome tutorials Brackeys!!! Thank you...

  • @cheesecakenl1980
    @cheesecakenl1980 7 років тому

    Again great quality and nice choice of content. Keep it up! @Brackeys

  • @abhisheksuper20
    @abhisheksuper20 5 років тому +1

    Damn!! This is some advanced next level stuff. Pretty cool :D

  • @Hydrolexo
    @Hydrolexo 7 років тому

    Free consistent and useful knowledge. Thank you Thank you Thank you Thank you Thank you

  • @Jenalgo
    @Jenalgo 6 років тому

    At 14:08 you state that objects will be derived from this interface. Firstly, objects are not derived. They are always instances of some class or other. Secondly, the correct way of stating what you meant to say is ... an interface contains a set of properties and methods, that all classes which conform to this interface, must implement. The reason for the distinction between 'derive' and 'implement' is because a class can only derive (inherit from) one parent class. But the class may 'implement' as many interfaces as it needs to.

  • @raulrusboy
    @raulrusboy 4 роки тому

    Why does this only work under fixedupdate for the cube spawner? Whenever I try to move it to a custom method to only spawn on an event, I get null reference exception...

  • @yt_superman7383
    @yt_superman7383 6 років тому

    Uses every bit of mental energy to keep up with Brackeys fast talking nonchalant code rambling while pausing the video a hundred times just to get the code right. Finishes all the code and everything is perfect, goes back to Unity and what did we accomplish? The cubes stopped spawning after 150 cubes.....

  • @tanmayupadhyay2027
    @tanmayupadhyay2027 4 роки тому +1

    OMG 😳! I just opened youtube to see object pooling... I just saw it in my home screen of youtube !

  • @kapkoder4009
    @kapkoder4009 4 роки тому

    Wow I've learned so many awesome things!

  • @noxu2441
    @noxu2441 4 роки тому +1

    I ran into a problem, they spawn, but they can't be seen. they aren't enabled to say. I went through checking code and trying to fix it but no luck so far. Anyone know why?

    • @paddyblack-exe
      @paddyblack-exe 4 роки тому

      Same issue on my end. When they spawn, the clones show up in the Heirarchy, but they are turned off in the inspector. Checking their box in the inspector makes them appear, but in Brackeys video they aren't turned on in the inspector either. They just appear in the game view :Z
      Did you find a solution?

  • @fa-pm5dr
    @fa-pm5dr 5 років тому

    this is some seriously useful stuff

  • @KadaXuanwu
    @KadaXuanwu 2 роки тому +2

    Why don't you just change the Start() method in the Cube class to OnEnable(), instead of using the interface?

  • @kokojacknouzian2231
    @kokojacknouzian2231 4 роки тому

    at 15:44 why does he type objectToSpawn.GetComponent() instead of just accessing objectToSpawn's OnObjectSpawn() method?
    I don't understand why he made an interface for it when he can just make a method in the class Cube, also another thing I don't understand is that he uses GetComponent() on an object that doesn't "contain" IPooledObject but rather inherits from it, I thought that was how GetComponent() works

  • @Dxpress_
    @Dxpress_ 7 років тому +2

    Instead of creating an interface for the cubes, couldn't you just set them to disable after a specified amount of time, then replace the Start method with the OnEnabled method?

  • @mustafasuve3109
    @mustafasuve3109 5 років тому

    At 16:22 How can we get rid of that GetComponent call?

  • @hammadnaeem6561
    @hammadnaeem6561 7 років тому +1

    Your tutorials are of great help.please make a video on shooting arrows in a 2d game that follows a parabolic trajectory. i am stuck in a project.It will help me a lot.
    Thank you

  • @wolfgangvyhmeister1995
    @wolfgangvyhmeister1995 6 років тому +1

    How you make it to a limitated amount of objects to be thrown?
    and for making it not to be destroyed I jsut have to take out the destroy.GameObject stuff ?

  • @baabaaer
    @baabaaer 4 роки тому

    6:27 Can I make the Pool class outside of the ObjectPooler class, or not?

  • @jasoncurry4821
    @jasoncurry4821 6 років тому +1

    I love it! Brackeys always makes the best videos. I extended ObjectPooler script to accept a list of game objects so I can have red cube, blue cube and green cube, etc. to the cubes pool.
    public class ObjectPooler : MonoBehaviour
    {
    [System.Serializable]
    public class Pool
    {
    public string tag;
    public List prefab;
    public int size;
    }
    public List pools;
    public Dictionary poolDictionary;
    // Use this for initialization
    void Start ()
    {
    poolDictionary = new Dictionary();
    foreach (Pool pool in pools)
    {
    Queue objectPool = new Queue();
    for(int i = 0; i < pool.size; i++)
    {
    //loop through the GameObject list inside the pool and instantiate each
    for(int a = 0; a < pool.prefab.Count; a++)
    {
    GameObject obj = Instantiate(pool.prefab[a]);
    obj.SetActive(false);
    objectPool.Enqueue(obj);
    }
    }
    poolDictionary.Add(pool.tag, objectPool);
    }
    }
    };