I spawned about 2000 zombies in my game. It says there are 2.3M vertices and 4.2M triangles being rendered. My frame rate is about 5 FPS.
Are there performance issues with having too many game objects? I turn off all objects that are far away (even their renderer). My far clip plane is only 150 (can’t see that far with fog on and everything). Their scripts are off because I can tell they’re not even moving.
Why is it so slow? If I have 1000 zombies, I get 11 FPS (2.2M triangles).
For example, you say “I turn off all objects that are far away”, so how many of the 2000 objects are visible? or are you saying that 2000 are visible after you’ve hidden the far-away objects?!
How many polys does each zombie use, and do they use animation?
Probably like 3 or 4 are visible. It seems like it’s still rendering the other objects. The far clipping is set to just 150. I also turned off the renderer.
Each zombie is about 2.2k triangles. Yes they have animations, but I turned off the Animation component (along with animation scripts). Does that disable the animation?
Okay I just tried a test, with 2000 5k objects (not animated), scattered randomly over a 1000x1000 plane.
I added the fps controller and took a walk. Performance was terrible because the default far clip plane is 1000, so most objects were visible in any given direction. Then I reduced the far plane to 100, resulting in a great framerate, with around 8-10 objects visible at any one time.
The vert poly count in the statistcs dropped accordingly too.
So this should work as you expect, and there seems to be something weird going on in your scene which is causing all the objects to be drawn in some way even when they’re beyond the far clipping plane.
Do you have more than one camera in your scene by any chance?
Yeah this is strange. I appreciate you helping me. I can’t figure out what’s causing it. I’m using only one camera.
One thing that I’m doing strange is that I’m using a trigger sphere collider (around the camera’s clipping range) to activate objects nearby and deactivate objects far away (turn off scripts, animations, etc). I thought this would be faster than scanning thru thousands of objects using the findobject function(or potentially tens of thousands).
Could this be the cause? I know the objects are deactivated because they aren’t moving. If I set the radius of this sphere to 10, I can see the objects disappearing when they’re too far away.Is there a better approach to finding nearby objects in a large scale world?
I tend to just cheat and only have the objects you can see actually be in the game. When objects behind the player get too far away, I spawn new ones in front, for example.
For the open-world space game I’m working on, I also created a trigger which moves all non-special objects that leave a certain radius to the other side. This way, a limited number of objects can infinitely move around you as you go straight in a certain direction.
Often, the best solutions are ones that don’t actually have anything in the world outside your frame of reference.
Well I figured out what it was. It was the projector I used for shadows. I forgot to turn those off. Now the triangle count and everything looks normal, but it didn’t help with performance too much. The frame rate is 8-10 FPS (compared to 5 FPS before).
How can I optimize this? How can I disable a game object completely (along with all the children objects and components)? Maybe it is best to instantiate the objects when I get close to them and then destroy them when they’re too far away?
They’re just completely gone. The way it handles it is by having a series of macro-boxes that tell the script how many items to shoot for. In the dense boxes, it could tell it to shoot for 80 asteroids on screen, for example.
With that in mind, when one is destroyed, it spawns another in a random location inside the boundary but outside the player’s vision. If the number is less than the goal, it spawns two. That way, it gradually moves towards the object goal.
You don’t need a master location for each object in the world, just general guidelines that your spawning script can work with. If something out of sight is supposed to affect something else, you’d handle it through variables instead of actual objects.