- Home /
Terrain with lots of objects
Hi, very new user ( only two days :) ) and being bugged with an issue.
I've got a standard Terrain, and I've been populating it with prefabs programmatically ( spelling corrected ;) thanks ! ) using Instantiate. The object is being created in a loop at random positions across the terrain, each one a sphere with 'is trigger' set to yes ( no physics ) and cast/receive shadows off.
This is fine with 25 spheres, but around a 1000 I take a real FPS hit ( using the fps detector from the wiki ). View is kept close, and fog is on, rarely are two or more spheres are visiable to the player.
Now, I plan to have a lot more than a 1000 :) so trying to head off this issue early. I don't want the spheres to do anything. My player will run into the spheres to collect them, therefore all the processing the player object does. The spheres just sit there being lazy, while the player does all the work ( collision detection is in my player game entity in OnTriggerEnter event ).
So, my question is, am I approaching this in the correct way? or is there an easier way of doing things rather than having thousands of spheres lagging my fps? Any comments/suggestions very very welcome :)
Edit : Stats :
As for the stats, the draw calls are in the 50-60s while moving, and fps has dropped so much ( this is with current build with only 400 spheres ). I'm guessing I'm doing something very wrong here :) When at rest, fps is fine, the moving is unplayable. Other stats that might be helpful :
Draw Calls: 50-60 Tris : 43.9k Verts : 24.5k Used Textures : 6 - 2.0 MB VRAM usage : 8.3 MB to 11.2 MB (of 0.5 GB) VBO Total : 152 - 0.9MB
If I comment out the Instantiate call for the spheres, draw calls fall to a constant 7, and there is no lag whatsoever. So its definately the spheres causing the problems.
Edit : Additional Info
Note : My camera is angled so it is top down, so Terrian blocks all view, and can't look up at the sky.
Placing all the spheres below the terrian, shoots up the draw calls to 433, tris, verts vram and vbo also shoots up. Still high frame rate while stopped, moving is reduced to a crawl.
Placing all the spheres above the terrian (and above camera) reduces draw calls to 7, tris to 3.4k, verts to 2.0k, Frame rate fine when still, dropping to a crawl on movement.
Removing the spheres altogether, and movement is fine and same fps as staying still. I really can't work out where the bottleneck is :S
Also, have you checked the number of draw calls in the scene? If you don't know how to - just click on "stats" in the top right corner of the game window. It's possible that Unity is rendering more than you think you would be able to see.
You're still wrong XD It's "Programatically", one 'm', not two. ;)
That is what it was to start with :) see, this is why I have such problems with it :) And thanks for the stats screen info, even though I had seen it in tutorials and screenshots, it never clicked that I could click on the stats button :) Will updated question with results from stats :)
Answer by JiffyJuff · May 18, 2013 at 07:09 AM
If the scripts are in the spheres, it's bad. I had a similar game, and in the end I reprogrammed everything so that the player object is the only thing with script. This will reduce the lag a lot. However, this doesn't completely solve the problem as as long as the objects exist, they take up space. I also don't know how to solve this.