Search Unity

Performance problem with Camera.Render and many objects

Discussion in 'General Graphics' started by DigitalToy, Sep 8, 2015.

  1. DigitalToy

    DigitalToy

    Joined:
    Oct 29, 2012
    Posts:
    11
    I am working on a kind of "paint splatter" program. I instantiate a lot of tiny objects (10s of thousands) to create an effect on the screen. I am finding that performance is slowing down to an unacceptable level. This happens after the objects are drawn on the screen - Camera.Render continues to use an enormous amount of CPU, even though the objects are static. The objects are all the same prefab, colored and sized differently. Is there a way to optimize this?
     
  2. LaJean

    LaJean

    Joined:
    Sep 6, 2015
    Posts:
    10
    Whenever large number of objects are to be drawn, expect lag. Just an idea: why not use particles?
     
  3. DigitalToy

    DigitalToy

    Joined:
    Oct 29, 2012
    Posts:
    11
    Thank you, I'll think about whether particles can solve it. However I'm still wondering why this happens - does the engine re-draw the objects every frame? I would have thought that once they are on the screen, and static, that the CPU usage would drop.
     
  4. LaJean

    LaJean

    Joined:
    Sep 6, 2015
    Posts:
    10
    1. Yes, the engine draws the object textures every frame, so you have to manually do the drawing "preservation". One way is to save periodically what you draw into a new texture and then set the texture so further drawing happens on it.
    Here's a start point: http://docs.unity3d.com/ScriptReference/Camera-targetTexture.html
    Note that rendering must be done every frame otherwise we wouldn't see it. The issue is drawing 10000 times or just 1 time per frame.
    2. I guess an equally dragging factor is the number of instances in the scene.

    Particles solves both problems, it just takes a bit to learn but it pays off big time (pun intended).
     
  5. DigitalToy

    DigitalToy

    Joined:
    Oct 29, 2012
    Posts:
    11
    Thank you for your help!
     
  6. imaginaryhuman

    imaginaryhuman

    Joined:
    Mar 21, 2010
    Posts:
    5,834
    Maybe the objects being sized different is breaking batching?