- Home /
optimizing huge amount of objects
Hey, I'm still here, that's my question: why FPS falls down to 2, if I have about 3000 game objects? They are far away from a camera, they are culled (per-layer) and invisible, so it's just 50-60 draw calls. They are trees and various vegetation, but I don't want to make an one mesh from them: every of them will have some script and animation. But now they don't have anything except meshes and materials (same for all), they're culled, and it's only 2 fps. What should I do to optimize this? Note: without joining to one mesh!
Answer by rutter · Jun 06, 2012 at 09:30 PM
every of them will have some script and animation
If you have several thousand objects, but are pretty sure that rendering isn't your bottleneck, then it's most likely the scripts or other components attached to those objects.
If you have Unity Pro, the profiler is invaluable in diagnosing this sort of problem. If not, you can try removing components one-by-one to see if any of them are a performance hotspot.
As I said, there are only rendering components on objects now. They have meshRenderer and $$anonymous$$eshFilter components. There is no to remove, I bet.
I can't get this, how do people optimize big forests, where every tree is individual object? On my spheric planet I've got even less trees, than you can find in Arma2, for example, or Warcraft3. What's the secret of making arrays of trees?
Ah, I missed that. Sorry.
Advice still more or less holds true, I think. Even if you're down to just two or three components per object, it will still help to identify which one(s) are causing the problem.
$$anonymous$$ost obvious problem is if all of those components are trying to render at the same time. Sounds like you're pretty sure that's not the case, so the next thing I'd look for is CPU load. Even efficient components can take up quite a bit of computer time if you're running several thousand of them at once.
Even if you don't have Unity's profiler, you may be able to find CPU/GPU/RA$$anonymous$$ metrics for your machine while the program is running. Could be useful to see which are getting maxed out.
I can just deactivate all of them. If I do this, FPS gets up to 40. But it's still not what I want: if there is no vegetation (if I remove them), fps is about 110-130. Why do even inactive objects take so much from machine..
$$anonymous$$eshRenderer causes all this fps breaking. But I can't remove it, trees just will not be rendered. What then? Has anyone on this Earth made a forest in own game?..
Answer by Mahamed9628 · Jun 07, 2012 at 10:48 AM
My experiments go well. For each tree I added script, which check distance between tree and camera every 2 seconds, and if distance is less than 100, it starts drawing cycle. Drawing cycle - function, which in cycle FOR calls method Graphics.DrawMesh, and then waits (yield WaitForSeconds(0.01). There is no update func. Drawing cycle goes on only if distance is less than 100. But here is some bug: with 0.01 trees flick. I'll try 0.001 or any other value. FPS is about 90-100. Good result.
So, my note: if number of game objects equals thousands (4000,5000) even empty objects will break fps down. I tried to put a lot of non-grouped (not joined to one mesh) grass, which has no components except transform, and FPS got to 1. I don't know, how people make so dense grass in so dense forests. Joining to one mesh also limited: Combine$$anonymous$$eshes function will return error if I try to join 5000-6000 meshes... If you've ever made dense forest, help me please with this.
Does anyone know how grass and trees get optimized in the Terrain class?