I'm currently developing a 2D top-down space themed RTS game. I'm building the space procedurally from a seed. At the end of generation of all space objects, if i don't apply any optimizations I end up with following result (all space objects are visible by camera):

full space no optimization

There are stars, planets, satellites as Sprite Renderers in the scene. And orbits of stars and planets as Line Renderers. Planets move around stars, satellites move around planets orbitally. Line Renderers of orbits are controlled and updated dynamically by a script to snap belonging object as it moves around parent orbit.

When i apply following logic to each renderer:

        if (MinVisibleDistance > mainCamSize || mainCamSize > MaxVisibleDistance)
            if (renderer.enabled)
                renderer.enabled = false;
            if (!renderer.enabled)
                renderer.enabled = true;

The results are much more happier (again, all space is visible by camera):

full space with custom distance culling

You can see a huge amount of saving in tris and verts count. But the problem with this logic is, even though the object is out of camera view, it gets enabled when camera zooms in. I think the "occlusion culling" option of Unity camera handles this problem, but I'm not sure if it has a performance impact either.

The question is; do this optimizations worth efforts? Or do they make performance even worse by if-else checks every frame and enabling-disabling components?

And are there other optimization ideas you can suggest?


  • \$\begingroup\$ Have you tested the performance of the different approaches with the Profiler? Any difference? \$\endgroup\$ – Mattias Jan 3 '16 at 22:38
  • \$\begingroup\$ @Mattias The results were too obvious that i didn't even need to do a profiling. But what i wonder is, will the optimizations keep "optimizing" after i complete the game? \$\endgroup\$ – S. Tarık Çetin Jan 4 '16 at 14:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.