- Home /
Cost of instantiation
So, I am making a game that requires most assets to be continually instantiated. Or, at least, partially. It is an infinite runner type game where all the obstacles are randomly generated.
My question is, what is the cost of instantiation? The assets themselves are low poly, most being under 500 polygons. (if that matters).
Furthermore, this is for mobile.
Answer by $$anonymous$$ · Jan 07, 2013 at 12:36 PM
Instantiation is high-cost, especially on mobile. You shouldn't use it continously. You should use object pooling instead, so you instantiate a bunch of stuff in advance, and store them in a pool, and from there you can re-use them, you can even randomly select objects from the pool. More info on this:
Simple Reusable Object Pool - Help limit your instantiations!
Video tutorial on Object Pooling
Do a search here or on the web, you'll find many more resources.
Thanks z_murc! I will pass this on to the programmer for him to peruse. :)
Answer by Piflik · Jan 07, 2013 at 01:03 PM
The complexity of instantiated objects doesn't make a noticeabel difference in my experience.
I don't have exact values, but as long as you don't instantiate multiple objects every fram, you might be fine, but I would run some tests on the target platform. If it doesn't work, you'd have to reuse objects instead of creating and destroying them, which might be a good idea anyway, because objects don't get cleaned up automatically and you need only a small number of each object simultaneously.
Yeah, the problem with our game is that we will be spawning objects constantly.
Your answer
![](https://koobas.hobune.stream/wayback/20220613090534im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Best Paying Interstitial Video Ads with Unity Bindings 1 Answer
Does PersistentDataPath get overwritten on mobile? 1 Answer
Accelerator.x rotating camera.z - problems with intermediate values 0 Answers
Mobile Orientation / input.acceleration problems 0 Answers
How do you implement UIToolkit into your own project? 1 Answer