- Home /
How to improve performance with a lot of same prefab?
To create a level geometry, I'm Instantiate prefab 4000 times at the start(). So my level geometry created, when level starts.
With that having very low framerate, although there nothing else in the level right now. The problem is Main thread, which keeps at ~330ms, although Renderer take just 2~4ms. Draw calls - 12, saved by batching - 2000. All other statistics at minimum or very low. What should I do to lower Main thread?
Please answer my question, it is vital information.
Also, is your "fab" object you assigned in the Inspector...
an object in your scene?
a model from the Projects tab?
a prefab from the Projects tab?
prefab, which I'm trying to instantiate, has no scripts. In scene just one script, it's "creation" script, which I posted below.
$$anonymous$$y "fab" is a prefab from project tab.
Thank you, found the case of my problem. That was the "Avatar" part of imported model. Switched "animation type" to "none" in inspector->import setting->Rig->animation type Wonder, why it's switched on by default for the model without animation. Hope this will be helpful for someone else. can you please submit answer tomy question, so I can mark it as answered?
I converted it to an answer. Glad you solved your problem!
Answer by Wolfram · Feb 05, 2013 at 03:59 PM
Then you need to find out what's special about that prefab. How does it differ from the actual model? Is it composed of several individual models? Other prefabs? Do the models have animations? Are there Colliders in the prefab?
(please respond to all questions, all have significance)
Yes, the problem was in model's animation. Avatar is imported for all models by default, and not needed to simple static models. Switched "animation type" to "none" in inspector->import setting->Rig->animation type. Solved.
$$anonymous$$udos to you. I wished everyone new to this site would care as much as you do about readability, and benefits for future readers! :o)
Answer by robertbu · Feb 04, 2013 at 05:47 PM
A couple of things to look into. Turning off the renderer on any object that are not currently being used will help. If some of the objects are static with respect to each other you can combine meshes. There are a couple of example scripts that are available when you install the standard asset package: in the "Standard Assets/Scripts/Utility Scripts" folder you will find CombineChildren and MeshCombineUtility scripts.
I attached CombineChildren script to parent of my prefabs, but it results only in prefabs no more visible. $$anonymous$$ain thread is still ~300ms
Do you have pro (and therefore run the profiler)? It sounds like the issues are not with the draw code, but something else.
No, I can't run profiler, but the situation is easily repeatebly with imported objects that you put in fab variable (my have 24 faces each). Can't create the same effect with Unity's GameObject->create other->Sphere, for example. So it has something to do with importing(from $$anonymous$$aya, in my case)
var fab : GameObject;
function Start () {
for (var i=0; i<4000; i++){Instantiate (fab, transform.position, transform.rotation);}
}
With Spheres I have $$anonymous$$ain Thread - 50 ms, Renderer - 20 ms, and this result seems normal.
You just instantiate them, nothing else? (especially transfor$$anonymous$$g them around via Animation or other scripts?)
@Wolfram I do what you said, a lot of static objects, without animating any. What do you see?
Your answer
Follow this Question
Related Questions
Huge Framerate Drop 0 Answers
Checking if object intersects? 1 Answer
Performance issues with grid based terrain 2 Answers
unity locks up when loading prefabs 1 Answer
Retina specific framerate drop on specific function 1 Answer