Spawning, or instantiation is making a new copy of an object into memory.
Let's take the example of bullet casings.
If every time you shoot, you create a new object, you can rapidly end up with thousands of the buggers on screen, in memory and chugging can occur.
With object pooling, however, you say... okay there are only ever N casings in memory. They are invisible, turned off but exist when you start the level. Let's say there are ten for this example.
When a gun first fires, it doesn't create a new bullet casing, it grabs the first casing from the pool, moves this to the guns position, makes it visible and throws it out into the world.
It then records the next free casing is number 2.
Another gun fires and casing 2 teleports to the gun, has its physics reset, becomes visible and flies off into the world to plink satisfyingly against the floor.
Next free casing is 3.
This continues until the pool runs out. When casing 10 is used, the pool returns to 1, (or 0) and the original casing is made invisible, teleports to the gun, is reset and made visible.
This means there is only ever 10 casings in the game. Ever.
Ever.
You can set up object pooling for pretty much everything in your game, including enemies, hit effects, spell effects, blood splats, sound effects... you name it.
Object pools give you clean control over memory allocation, frame rate and hiccups when you instantiate.
Object pools can be passed enemy types, different artwork, different stats and abilities, but enemy01 is always enemy01 regardless of if it is playing a goblin, a zombie or a chainsaw knight riding on a chicken.
If you have a pool of 8 enemies, you won't ever get more...
Than 8 enemies on screen. Until you kill some of them, or they unload and clean the pool.
• • •
Missing some Tweet in this thread? You can try to
force a refresh
Typical exploits I use on student projects to highlight issues are:
□ On infinitely thin modular walls, go into a corner and press directly against it and ease the direction stick back and forth to get a character to pop through and out of bounds.
□ Find where two physics...
...objects interact and get the player inside that fun crush.
□ abuse the capsule collider to levitate the character just outside of a platform and creep around puzzles.
□ spam damage on a wall to see if I can spawn infinite damage decals.
□ draw dicks with trails.
□ see if crouching in a corner puts me outside of enemy hitbox attacks.
You can avoid tessellation popping on terrain by subdividing the mesh without smoothing then interpolating the curve based on camera distance. This essentially warps objects smooth, but movement often covers this in the players mind.
Sudden changes attract the eye, but warping slowly does not. We have to concentrate to notice this.
This trick can be used to make LOD meshes transition too, using a vertex displacement or blend shape. Worth it for very large objects.
If you are learning game development you absolutely have to watch speed runner and glitch hunting videos. Let's Game It Out is also a must watch- not just because he is hilarious, but because he is a razor sharp QA brain. He breaks games as easily as others breath.
*breathe.
Watching people exploit games puts you face to face with the flaws in thinking you will make as you solve problems.
Simple things like... okay I will store the x,y,z position of the player on save, then check to see which zone that is in when I load.
Classic examples of how that can be broken are falling damage cancellation quitouts in Darksouls, or sitting on a chair pressed up against the bars of crypt in Valheim.
I can't go frame by frame here but it looks like being rapidly pushed into an unloaded area.
Actually you can see the yellow trim vanish and then the floor.
I suspect the actual character is technically falling out of bounds despite the mesh being fixed for the camera shot, and the position is causing the scene to LOD and unload.