- Home /
Instantiate objects on iPhone affecting performance, strategy.
So I have a mesh, I instantiate this prefab/mesh on a regular basis every 3 seconds as a new object. They destroy themselves every 4 or 5 seconds later to clean up.
Problem is (on the iPhone) the whole game freezes for a moment while that object is instantiated. I notice that each object adds a draw call also.
Question is basic strategy. If I need lots of objects, using the same prefab/mesh what is the best way to introduce them to the scene? Is there a way to prevent separate draw calls for each one?
I've thought about instantiating a bunch on load and hide them off camera. Showing and hiding as needed, but I would still require a bunch of draw calls for the objects I think.
Answer by BoredKoi · Jun 23, 2010 at 11:27 AM
So I have a mesh, I instantiate this prefab/mesh on a regular basis every 3 seconds as a new object. They destroy themselves every 4 or 5 seconds later to clean up.
That's what is killing your performance; instantiate your objects on Start() and then disable the ones you don't need. Things off camera will not cost you draw calls; your last comment about showing/hiding is what you want to do. Excessive Destroy() calls will just lead to Garbage Collection while your scene is running, and the frame rate will stutter significantly.
If I need lots of objects, using the same prefab/mesh what is the best way to introduce them to the scene? Is there a way to prevent separate draw calls for each one?
Objects with a relatively low face count and sharing the same material will be dynamically batched, meaning 1 draw call. Other options include combining meshes (CombineChildren script, for example).
The Reference Manual has a dedicated section on Graphics optimization: Graphics Optimization
found that useful too, as I have EXACTLY the same problem. Thanks
Your answer
Follow this Question
Related Questions
2D Pathfinding: how to create navMesh 0 Answers
ex2D performance 1 Answer
Instantiating Too Many Objects 1 Answer
Can't seem to destroy instantiated objects. 1 Answer
Lagging on iphone 4 while worked well on iPhone 3GS and 4S 1 Answer