Search Unity

Why low frame rate?

Discussion in 'Getting Started' started by narf03, Apr 28, 2015.

  1. narf03

    narf03

    Joined:
    Aug 11, 2014
    Posts:
    223

    each color block is made up from ~1200 quads, so there are ~15,000 quads(separated into multiple gameobjects, so there are 15k+ Gameobjects in the scene), uses only 5 draw calls, wondering why my FPS only 12-13. What is slowing it down ?
     
    Last edited: Apr 28, 2015
  2. Ryiah

    Ryiah

    Joined:
    Oct 11, 2012
    Posts:
    21,205
    GameObjects are heavy on resources. You shouldn't be using them so heavily. At most I would recommend no more than one for each of the color blocks. They are entirely the reason your performance is that bad.
     
    Kiwasi and hippocoder like this.
  3. narf03

    narf03

    Joined:
    Aug 11, 2014
    Posts:
    223
    But when i turn my camera away from them, seeing nothing of them, i get ~40fps, all the gameobjects still there(in the scene). its still slow, but not ~12fps. I m doing this trying to understand what slow things down and try to learn how to avoid them.
     
  4. Ryiah

    Ryiah

    Joined:
    Oct 11, 2012
    Posts:
    21,205
    It may be they're being culled out prior to the stage where they cause problems. I don't actually know how they're handled internally, but I do know the performance problem involves them.
     
    Last edited: Apr 28, 2015
  5. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Any why low framerate questions should be replied with "show profiler" :) But agree with Ryiah's suggestions.
     
    Kiwasi and Ryiah like this.
  6. Ryiah

    Ryiah

    Joined:
    Oct 11, 2012
    Posts:
    21,205
    Yes, I really should but most of the time it seems to revolve around GameObjects being used like this. :p
     
  7. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Really, Unity should be able to handle a few thousand draw calls and far more gameObjects. It's probably transform that's the cost penalty here since moving a child will evaluate everything including parents. Then there's culling. Unity has a lot of scenegraph optimisations to do.
     
  8. narf03

    narf03

    Joined:
    Aug 11, 2014
    Posts:
    223
    couldnt tell from the profiler, it says rendering take most of the "cpu time", but im pretty sure it can do alot more tris and verts.
     
  9. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Tris and Verts only matter once you're into the million mark on a modern desktop. It's more about draw calls, optimisations etc

    In the above shot it looks like a lot is saved by batching. If using static batching, you stress culling performance, which is why static batching is often best reserved for larger chunky pieces that should still cull. Dynamic batching can also suffer because preparing a dynamic batch still takes time.

    Ideally just make a single mesh and it should run absolutely fine.

    All things in moderation.
     
    Ryiah likes this.
  10. narf03

    narf03

    Joined:
    Aug 11, 2014
    Posts:
    223
    Ya, as a single mesh, i should be getting full FPS without any issue, but the purpose of this is, I want to know the limitation and avoid it in the future. At this moment, all i can say 15k GameObject is slowing things down, and 15K isnt alot, assuming 1 3D model has 100-200 smaller GameObjects, putting 100 of them on the scene will hit this limit.
     
  11. Ryiah

    Ryiah

    Joined:
    Oct 11, 2012
    Posts:
    21,205
    GameObjects are CPU-side. Actual rendering is through the MeshRenderer component.

    Yes, it is a lot.

    One model does not have 100 to 200 smaller GameObjects. It only has one GameObject. GameObjects are not restricted to a single triangle or quad.
     
    Last edited: Apr 28, 2015
    Kiwasi likes this.
  12. narf03

    narf03

    Joined:
    Aug 11, 2014
    Posts:
    223
    I dont understand how do you count, for example in this image below, how many gameobjects are in the scene ?
     
  13. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    What on earth are you attempting to build? As a general rule the more things you put on the screen the simpler they have to be. Throwing hundreds or thousands of things on screen means each individual thing has to be simple.

    Watch how RTS games do it. Each unit is very simple.
     
  14. narf03

    narf03

    Joined:
    Aug 11, 2014
    Posts:
    223

    currently the problem happen even they arent on the screen, as long as those 15k items in the same scene(camera has nothing), fps drops too.
     
  15. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    That isn't remotely his bottleneck though. Putting thousands of things on screen with 100 polys each would probably perform pretty much the same as 1,000 polys each. Modern GPUs process this stuff at a frightening rate - the slow down comes from interrupting it or being slow to feed it.
     
  16. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Post profiler as anyone with a brain won't help you further without it. Guessing this stuff is kind of dumb when you have hundreds of thousands of dollars of profiler engineering built into unity.
     
    Kiwasi likes this.
  17. narf03

    narf03

    Joined:
    Aug 11, 2014
    Posts:
    223
    Oh ok
     
  18. narf03

    narf03

    Joined:
    Aug 11, 2014
    Posts:
    223
    When i turn my camera away, im getting very high FPS in the statistics, but my code below only shows ~35FPS, when i delete all gameobjects on screen, i get 60FPS from the code.
    void OnGUI() {
    GUI.Label(new Rect(1, 1, 100, 20), (1f / Time.deltaTime).ToString());
    }


     
  19. Schneider21

    Schneider21

    Joined:
    Feb 6, 2014
    Posts:
    3,512
    I'm dying to throw some thought at this, but none of @narf03's images are showing up for me.
     
    Kiwasi likes this.
  20. Ryiah

    Ryiah

    Joined:
    Oct 11, 2012
    Posts:
    21,205
    You must have the same weird problem I do. Some sites, such as postimg.org, don't show up in any browser for me except for Internet Explorer. I have a similar problem with Amazon and NewEgg. No idea why either.
     
  21. Schneider21

    Schneider21

    Joined:
    Feb 6, 2014
    Posts:
    3,512
    Ah, you're right. So if I inspect the broken images and copy the links out, I can load them in a new tab. Very strange.
     
  22. Schneider21

    Schneider21

    Joined:
    Feb 6, 2014
    Posts:
    3,512
    You're right: Armatures/Skeletons are basically just empty Game Objects whose Transform property is used to displace a Skinned Mesh Renderer. I think Ryiah was probably referring to objects with a MonoBehavior component. Empty transform objects are fairly low overhead, I imagine, as they're more or less just the same as 3 Vector3s.

    Related note: That seems like a very detailed skeleton for such low-poly models... You certainly wouldn't find that much detail in characters you'd see in most games that throw a ton of them on screen.
     
    Ryiah likes this.
  23. Ryiah

    Ryiah

    Joined:
    Oct 11, 2012
    Posts:
    21,205
    I am not entirely awake at the moment, so I didn't even think about character models. :p
     
  24. Schneider21

    Schneider21

    Joined:
    Feb 6, 2014
    Posts:
    3,512
    Well I thought the same thing as you, initially (I'm only ever half awake, at best). "200 Game Objects per model?! Are you nuts?!" But I doubt most armatures would have even 100 bones. More like... 50 for a detailed humanoid?

    Regardless, I have to believe bones are handled much differently than objects with renderer and/or script components, so I don't think 10 rigged models is equivalent to 500 scenery objects.
     
  25. Ryiah

    Ryiah

    Joined:
    Oct 11, 2012
    Posts:
    21,205
    You won't be rigging every single model in your scene either.