Skip to content
0:00 / 0:00

#unity#objectpooling#c#

[Unity 5] Object Pooling Tutorial

Sebastian Lague

1.4M subscribers • 11 videos on Hallway

YouTube
  • Recommended by 1 person: 1 on Stack Overflow and its sister sites.
  • Presented by Sebastian Lague
  • Linked in the descriptionSebLague/Object-Pooling
  • May be out of date. The tools, versions or practices it shows have likely moved on.

Intermediate. Assumes working knowledge.

65K views10 years ago1 recommendation

Game developmentSoftware designGame programmingDesign patternsPerformance and optimization

Sebastian Lague explains how to implement and use object pooling in Unity to optimize game performance by recycling objects.

Object pooling is an optimisation technique which is extremely helpful for boosting the performance of mobile games. The basic idea is to recycle a pool of objects, rather than continually instantiating and destroying new ones. UPDATE: At ~ in the video, the lines copied should preferably be pasted BEFORE the call to OnObjectReuse(), so that when that method is called, the object will already have its correct position/rotation values. This could be important when resetting certain things, for example the velocity of a projectile based on its initial rotation. Source code: github.com/SebLague/Object-Pooling Support my videos on Patreon: bit.ly/sebPatreon

Why it's here

1 person recommends this

What people say. Recommended as a clear explanation of how to implement object pooling in Unity to avoid expensive instantiation calls.

Kevin H.on Game Development Stack Exchange • Recommends

On “Why should I always consider creating and using object pools instead of instantiating the new object on the fly?”

If you're planning to instantiate many instances of the same prefab, you should definitely think about using object pooling. Calling Unity's Instantiate function is one of the most taxing method calls you could make. Object pooling is when you instantiate prefabs before they are used. They are deactivated immediately upon instantiation and reactivated only when they are needed. While this does increase memory usage, it avoids the CPU overhead of instantiating during gameplay. For example, I'm currently working on a bullet hell game that requires hundreds of bullets to be spawned at runtime. I initially tried to make the game without object pooling but that ended up being a disaster ( les…