Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

reason of high cpu usage

Discussion in 'Editor & General Support' started by felsi, Nov 27, 2014.

  1. felsi

    felsi

    Joined:
    Jul 3, 2013
    Posts:
    15
    Hello!

    I hope this is the accurate forum for my issue...

    I can't find the reason why my game is slow as hell.
    The FPS drops under 5!!!

    Draw Calls: max. about 250 Saved by batching: up to 1300
    Tris: under 350k Verts: under 200k
    Used Textures: max 5 2,7MB
    VRAM usage: 3,7MB to 25,8MB
    VBO Total: 2706 - 19,4MB
    Shadow Casters: 0
    Visible Skinned Meshes: 0

    It's a multiplayer game.
    State control is only used for the low-poly player. Everything else in the scene is static. (see batching...)
    At the beginning i use Network.Instantiate a few 100 times, so the traffic after 15 seconds is:

    bytes sent: about 70k
    bytes received: about 10k
    message bytes queued: about 50k

    After playing 2 Minutes without any further use of Network.Instantiate:

    bytes sent: about 120k
    bytes received: about 60k
    message bytes queued: about 80k

    There are max 2 Players and they only use the build-in Character Controller, Mouse Look, Character Motor and FPSInput Controller scripts.

    CPU usage without testing the game: about 10%
    (old slow pc(AMD A4-3300), but thats ok, it should run on android and iphone)

    Running a single (builded) instance of the game (all Objects instantiated):
    CPU usage: 90% to 100%
    Running two instances(Server and Client):
    CPU usage: always 100%
    Running two instances on 2 PCs(Server and Client):
    CPU usage: 90% to 100%

    I don't use the Update-function in any of my self written scripts.
    No infinite loops in other functions.
    And only 2 OnTriggerEnter with 3 lines of code.

    If someone could gave me a hint how to reduce CPU-usage, i would be very happy :)

    Thank you in advance
     
    Last edited: Nov 27, 2014
  2. Carpe-Denius

    Carpe-Denius

    Joined:
    May 17, 2013
    Posts:
    842
    Which unity version? free or pro? In the window where you got the stats (draw calls etc.) there is information how much time your cpu and gpu need.
    What does it say?

    What are you instancing? Physic objects?
     
  3. Arowx

    Arowx

    Joined:
    Nov 12, 2009
    Posts:
    8,194
    Also what is the taskmaster in windows showing as the main CPU hogs?
     
  4. Neoku

    Neoku

    Joined:
    Oct 27, 2014
    Posts:
    261
    If you use Unity pro use the profiler tool, if not well, try divide your game in small parts for analize one by one and found the problem.
     
  5. felsi

    felsi

    Joined:
    Jul 3, 2013
    Posts:
    15
    Thank you for the fast replies

    I use Unity Free 4.5.5f1
    Therefor i can't use the profiler...

    Main thread: something between 50 and 300ms (average: 100ms)
    Renderer: something between 3 and 20ms

    I use the Network.Instantiate for 4 different prefabs, which only constist of simple static planes. (for walls in a labyrinth)
    And for 2 simple Players.
    This is all the scene consists of.

    At the startup there is a lot to do for the cpu (calculating a new lab, etc.).
    But after this i have no idea why the game is so slow.
    None of my scripts are involved anymore.
     
  6. carking1996

    carking1996

    Joined:
    Jun 15, 2010
    Posts:
    2,605
    Why not disable scripts to see how they are affecting it? One by one.
     
  7. felsi

    felsi

    Joined:
    Jul 3, 2013
    Posts:
    15
    I disabled all self-written scripts (no problem, because none of them is doing anything after building the lab) and the performance is still the same. Thank you for the hint anyway :)
     
  8. Arowx

    Arowx

    Joined:
    Nov 12, 2009
    Posts:
    8,194
    Try Cubemark (link in sig) to see what score your system gets using Unity and what CPU load it uses without networking.
     
    felsi likes this.
  9. felsi

    felsi

    Joined:
    Jul 3, 2013
    Posts:
    15
    Thank you!

    Fastest: 35,204 25,475
    Fast: 28,608 24,060
    Simple : 26,282 24,550
    Good: 26,034 24,751
    Beautiful: 25,859 24,844
    Fantastic: 25,507 24,210

    I closed all other programs while running the benchmark in firefox.
    Unfortunately i don't know how to interprete the result.

    But i also tried to run my game on 2 different pcs and closed all other programs, inclusive the Unity Editor. It ran much better and the cpu usage was around 40%. The other pc(debian) has an i5, so there it ran pretty well anyway. (without a graphic card)

    Maybe at the end the problem is no problem, but a damn slow pc...
     
    Last edited: Nov 28, 2014
  10. Arowx

    Arowx

    Joined:
    Nov 12, 2009
    Posts:
    8,194
    Actually think about it your machine can spin around 24k cubes in Unity @ 60fps. What CPU load was it showing on the task manager with the benchmark running?

    This could pin the problem down to it being the networking code, generating too much traffic. You mention network instantiating 100 objects thats 100 things you want the networking system to monitor and update on both machines. You could be updating 200 objects on both machines.

    Check on the networking forums for advice for optimising networking bandwidth, I'm guessing you can reduce this overhead using RPC's Remote Procedure Calls that trigger data updates that work at a higher level. e.g. Send a move command as opposed to updating the transform position of objects every frame.

    Also if your game is being run standalone, you might want to try the standalone version of the benchmark.
     
  11. AlanMattano

    AlanMattano

    Joined:
    Aug 22, 2013
    Posts:
    1,500
    Physics
    A static object is moving?

    if pc old look for post process effect and disable them
     
  12. Arowx

    Arowx

    Joined:
    Nov 12, 2009
    Posts:
    8,194
    You can actually download the trial Pro version of Unity for the profiler, and even if you have tried the trial version Unity often offer trail codes for prominent game jams.
     
  13. felsi

    felsi

    Joined:
    Jul 3, 2013
    Posts:
    15
    Like AlanMattano mentioned, all objects beside the two players are static and don't cause any traffic. Maybe i'll try to reduce the traffic anyway by interpolating the position...
    In the meantime i tried the game on my htc one s, it's working, but not as smooth as i expected.
    But at the pc i achieved a framerate about 70fps, i forgot to make some empty parenting objects static...

    Yes, i already tried the trial version last year...
    Thanks for the hint, i'll ask.
     
    Last edited: Nov 29, 2014
  14. felsi

    felsi

    Joined:
    Jul 3, 2013
    Posts:
    15
    While the performance is pretty well when i look in a direction where no other object is behind the currently seen object, it stutter when i look in a direction where the whole labyrinth is behind, so i think occlusion culling could increase the performance relevant...