0
\$\begingroup\$

I am making an RTS game which has a slowdown when many units are on screen at once. I have a plan to write my own camera script to speed this up.

Since I have an efficient way to find where units are without the raycast, I want to write scripts to replace the camera and check raycasts against only the few objects that my scripts will identify as in the correct area for that raycast?

Alternatively is is possible to have the camera ignore certain entities on one part of the screen, and then a different set on another part of the screen?

--Edit-- I am very grateful for people helping in anyway, but I wanted to know if this Could be done even if in my case it shouldn't be.

\$\endgroup\$
  • 1
    \$\begingroup\$ Culling is essentially based on distance in Unity you can not cull a part of screen but you can cull units that are 100 meters far from the camera for example \$\endgroup\$ – buffalo94 May 16 '18 at 8:10
  • 1
    \$\begingroup\$ The built-in camera doesn't do raycasting at all, unless you're talking about firing OnMouseOver / OnMouseDown MonoBehaviour methods. What profiling have you done to identify the camera as the bottleneck in your rendering? \$\endgroup\$ – DMGregory May 16 '18 at 10:42
  • \$\begingroup\$ @DMGregory It is not the bottleneck, but on the profiler the CameraRenderer is taking 7-12 milliseconds per frame, which I want to cut down as much as possible. I'm not sure what to google to find how the unity camera actually works, do you have a hint? :) \$\endgroup\$ – PStag May 16 '18 at 12:43
  • 1
    \$\begingroup\$ Usually when you have a ton of GameObjects performance hits are at the processing layer, not the rendering layer. Rendering performance is directly related to how many objects exist in the frustum, and how many post processing passes you have to do for filters. Even those are stupid fast. How many objects are in the frustum when you profiled it, and how does the performance change with fewer and more objects? Essentially we're going to need some data. \$\endgroup\$ – Stephan May 16 '18 at 18:48
  • \$\begingroup\$ The camera's main jobs in Unity are filtering objects by layer and frustum culling, (including some related frustum optimizations like pausing animation/particle system updates when they're off-screen), and providing transformation info selecting LoD levels and for the shaders to map models onto the screen. I don't expect a custom C# script could be injected into this flow and do these tasks faster than the built-in version. If you dig deeper into profiling you should see blocks related to rendering steps like opaque & translucent or post-process passes — does anything stand out there? \$\endgroup\$ – DMGregory May 17 '18 at 11:43

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.