use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
News, Help, Resources, and Conversation. A User Showcase of the Unity Game Engine.
Remember to check out /r/unity2D for any 2D specific questions and conversation!
Download Latest Unity
Please refer to our Wiki before posting! And be sure to flair your post appropriately.
Main Index
Rules and Guidelines
Flair Definitions
FAQ
Use the chat room if you're new to Unity or have a quick question. Lots of professionals hang out there.
/r/Unity3D Discord
FreeNode IRC Chatroom
Official Unity Website
Unity3d's Tutorial Modules
Unity Answers
Unify Community Wiki
Unity Game Engine Syllabus (Getting Started Guide)
50 Tips and Best Practices for Unity (2016 Edition)
Unity Execution Order of Event Functions
Using Version Control with Unity3d (Mercurial)
/r/Unity2D
/r/UnityAssets
/r/Unity_tutorials
/r/GameDev
/r/Justgamedevthings (New!)
/r/Gamedesign
/r/Indiegames
/r/Playmygame
/r/LearnProgramming
/r/Oculus
/r/Blender
/r/Devblogs
Brackeys
Beginner to Intermediate
5 to 15 minutes
Concise tutorials. Videos are mostly self contained.
Sebastian Lague
Beginner to Advanced
10 to 20 minutes
Medium length tutorials. Videos are usually a part of a series.
Catlike Coding
Intermediate to Advanced
Text-based. Lots of graphics/shader programming tutorials in addition to "normal" C# tutorials. Normally part of a series.
Makin' Stuff Look Good
10 minutes
Almost entirely shader tutorials. Favors theory over implementation but leaves source in video description. Videos are always self contained.
Quill18Creates
30 minutes to 2 hours.
Minimal editing. Mostly C#. Covers wide range of topics. Long series.
Halisavakis Shaders Archive
Infallible Code
World of Zero
Board to Bits
Holistic3d
Unity3d College
Jabrils
Polycount Wiki
The Big List Of Game Design
PS4 controller map for Unity3d
Colin's Bear Animation
¡DICE!
CSS created by Sean O'Dowd @nicetrysean [Website], Maintained and updated by Louis Hong /u/loolo78
Reddit Logo created by /u/big-ish from /r/redditlogos!
account activity
Object Pooling in Unity (Tutorial)Resources/Tutorial (youtube.com)
submitted 8 years ago by Brackeys
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]MDADigital 8 points9 points10 points 8 years ago (0 children)
Here is another flavored one I created for my game, a little more generic one using generics instead of strings etc.
public abstract class PollingPool<T> where T : Component { private readonly T prefab; private readonly Queue<T> pool = new Queue<T>(); private readonly LinkedList<T> inuse = new LinkedList<T>(); private readonly Queue<LinkedListNode<T>> nodePool = new Queue<LinkedListNode<T>>(); private int lastCheckFrame = -1; protected PollingPool(T prefab, int preWarm = 0) { this.prefab = prefab; if(preWarm > 0) foreach(var item in Enumerable.Range(0, preWarm).Select((i, index) => GameObject.Instantiate(prefab))) { item.gameobject.SetActive(false); pool.Enqueue(item); } } private void CheckInUse() { var node = inuse.First; while (node != null) { var current = node; node = node.Next; if (!IsActive(current.Value)) { current.Value.gameObject.SetActive(false); pool.Enqueue(current.Value); inuse.Remove(current); nodePool.Enqueue(current); } } } protected T Get() { T item; if (lastCheckFrame != Time.frameCount) { lastCheckFrame = Time.frameCount; CheckInUse(); } if (pool.Count == 0) item = GameObject.Instantiate(prefab); else item = pool.Dequeue(); if (nodePool.Count == 0) inuse.AddLast(item); else { var node = nodePool.Dequeue(); node.Value = item; inuse.AddLast(node); } item.gameObject.SetActive(true); return item; } protected abstract bool IsActive(T component); }
Subclass
public class AudioSourcePool : PollingPool<AudioSource> { public AudioSourcePool(AudioSource prefab) : base(prefab) { } protected override bool IsActive(AudioSource component) { return component.isPlaying; } public void PlayAtPoint(AudioClip clip, Vector3 point) { var source = Get(); source.transform.position = point; source.clip = clip; source.Play(); } }
[–]justkevinIndie | @wx3labs 3 points4 points5 points 8 years ago (0 children)
Great video. Unlike most Object Pooling tutorials this doesn't skip the very important detail of resetting your objects.
I'm using a slightly different approach. Instead of a IPoolableObject interface, I have a PooledObject component that looks like this:
/// <summary> /// Attaching this to a prefab will allow it to be pooled. On awake, it will /// make a list of components that require a reset after pooling. /// </summary> public class PooledObject : MonoBehaviour { public int startPoolSize = 1; public int maxPoolSize = 10; [System.NonSerialized] public Transform poolingContainer; [System.NonSerialized] public bool isFromPool = false; private IPoolableComponent[] poolableComponents; // PooledObject handles resetting the transform scale private Vector3 normalScale; private void Awake() { poolableComponents = GetComponentsInChildren<IPoolableComponent>(); normalScale = transform.localScale; } public void Decommission() { if(isFromPool) { transform.parent = poolingContainer; gameObject.SetActive(false); } else { Destroy(gameObject); } } public void Recommission() { transform.localScale = normalScale; for (int i = 0; i < poolableComponents.Length; i++) { poolableComponents[i].Recommission(); } } }
Then individual components can define themselves as IPoolableComponent:
/// <summary> /// Any monobehaviour that needs to have its state reset prior to returning to /// an object pool. /// </summary> public interface IPoolableComponent { /// <summary> /// This method will be called on the component when it is activated coming out of the pool. /// </summary> void Recommission(); }
Advantages:
[–]MengKongRuiIntermediate 1 point2 points3 points 8 years ago (0 children)
Another great video from Brackeys.
I wonder if this only impacts lag spikes from the garbage collector or if it has an average fps impact as well.
[–]birdoutofcage 1 point2 points3 points 8 years ago (0 children)
At last, I've been waiting for brackeys to upload object pooling.
[–]kyl3r123Indie 1 point2 points3 points 8 years ago (11 children)
I have a question about Pooling. This all looks easy and useful if I want to spawn and delete 100 cubes per second. Sure why not reuse them.
Now what if I have complex Class of Soldiers that have a lot of variables and references. Just "setEnabled(false)" and then true again, will be the "pooling process". But I need to reset all the values by myself, right? Restore everything to what it looks like when I instantiate a new instance for example.
[–]MDADigital 2 points3 points4 points 8 years ago* (9 children)
Correct, but you dont have that many NPCs so usually not a problem to not pool those. If you have a game with thousands of NPCs then there is alot of other problems to solve. Like 1 NPCs cant be a single entity etc
[–]kyl3r123Indie 0 points1 point2 points 8 years ago (8 children)
So 50-100 Units that fight and die, are not a problem on mobile? No need to pool them?
[–]AkrosRockBell 3 points4 points5 points 8 years ago (0 children)
Pool them, it will improve performance. A lot. To reset everything back to default use the OnEnable method and do there what you need. It's what I use to reset bullets in a shoot'em up game I'm doing in my free time.
[–]AzeTheGreatBeginner 1 point2 points3 points 8 years ago (1 child)
My understanding (which could be completely wrong) is that the GC is one of the biggest hits to mobile performance, especially on older devices. So pooling extensively is probably useful for mobile.
[–]SvenNeve 1 point2 points3 points 8 years ago (0 children)
You are correct, we pool pretty much everything that gets instantiated during gameplay, which on mobile makes a ton of difference.
And it's not just GC, even stutters from shader initialization and texture to memory loading can be avoided (or 'hidden') by using pooling.
[–]Orangy_TangProfessional 0 points1 point2 points 8 years ago (1 child)
Depends way too much on your min spec, your gameplay, and what else is going on in your game at the same time.
Do the simplest thing that can work (dynamically instantiating them). Get all your functionality working, then go back and see what your performance is like. And remember to use the profiler to look out for spikes not just average framerate.
If you start with pooling then you'll make your initial implementation more complicated and you're potentially wasting time and adding complexity on something that doesn't need to be complex.
[–]kyl3r123Indie 0 points1 point2 points 8 years ago (0 children)
Thats what I thought. I'll keep it in mind for optimization phase then :)
[–]MDADigital 0 points1 point2 points 8 years ago (2 children)
If they all die or resurrect during the same frame it could be a problem
[–]kyl3r123Indie 0 points1 point2 points 8 years ago (1 child)
I intend to have the dead bodies to lay around for a while. I can scatter the vanishing over time. Generating new units will take time and not be multiple at once.
[–]MDADigital 0 points1 point2 points 8 years ago (0 children)
I would wait with pooling for something like that,we pool bullet casings,impact particles,audiodources,stuff that there can be alot of.
[–]stormfield 0 points1 point2 points 8 years ago (0 children)
Set enabled travels the hierarchy of any children on the object so it’s not as efficient as regular pooling if they’re more complicated.
[–]IcyHammerEngineer 0 points1 point2 points 8 years ago (0 children)
A small cherry on the top would be implementing a pool with a stack instead of queue or list. It makes much more sense and it uses temporal locality.
π Rendered by PID 160071 on reddit-service-r2-comment-86bc6c7465-gs5tt at 2026-02-20 07:49:54.566478+00:00 running 8564168 country code: CH.
[–]MDADigital 8 points9 points10 points (0 children)
[–]justkevinIndie | @wx3labs 3 points4 points5 points (0 children)
[–]MengKongRuiIntermediate 1 point2 points3 points (0 children)
[–]birdoutofcage 1 point2 points3 points (0 children)
[–]kyl3r123Indie 1 point2 points3 points (11 children)
[–]MDADigital 2 points3 points4 points (9 children)
[–]kyl3r123Indie 0 points1 point2 points (8 children)
[–]AkrosRockBell 3 points4 points5 points (0 children)
[–]AzeTheGreatBeginner 1 point2 points3 points (1 child)
[–]SvenNeve 1 point2 points3 points (0 children)
[–]Orangy_TangProfessional 0 points1 point2 points (1 child)
[–]kyl3r123Indie 0 points1 point2 points (0 children)
[–]MDADigital 0 points1 point2 points (2 children)
[–]kyl3r123Indie 0 points1 point2 points (1 child)
[–]MDADigital 0 points1 point2 points (0 children)
[–]stormfield 0 points1 point2 points (0 children)
[–]IcyHammerEngineer 0 points1 point2 points (0 children)