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

High CPU usage

Discussion in 'Editor & General Support' started by mado0211, Nov 10, 2018.

  1. mado0211

    mado0211

    Joined:
    Nov 10, 2018
    Posts:
    2
    I run my game in Unity Editor 2018.2.15f1 takes 10 ~ 15% CPU
    However, I build a exe for PC, Mac & Linux standalone. This exe take 60%~75% CPU.
    I created a new project and didn't add anything to it, it's a empty project.
    This issue happened too.
    How can I reduce the cpu usage?
     
  2. DaDonik

    DaDonik

    Joined:
    Jun 17, 2013
    Posts:
    258
    Could be that your .exe is running the game as fast as it can, which would result in more CPU usage, as well as probably 100% GPU usage.
    Add the following line to one of your MonoBehaviours Awake() or Start() method.
    Code (CSharp):
    1. Application.targetFrameRate = 60;
    That should make it run as fast as in the editor, if you have a 60Hz monitor, or haven't altered the refresh rate in windows.
     
    Dinky likes this.
  3. mado0211

    mado0211

    Joined:
    Nov 10, 2018
    Posts:
    2
    Code (CSharp):
    1. Application.targetFrameRate = 60;
    Thank you. It solve my issue.
     
  4. Lurking-Ninja

    Lurking-Ninja

    Joined:
    Jan 20, 2015
    Posts:
    9,930
    In reality you never had an issue. It's just a perceived one.
     
    Joe-Censored likes this.
  5. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Application.targetFrameRate is not really a good solution, since it makes things annoying for people with >60Hz screens. Use vsync instead. Or at least if you want a 60fps cap, make it an option.

    Well, no, excessive CPU/GPU usage drains batteries and causes heat/noise problems, it's a real issue that shouldn't be ignored.

    --Eric
     
    Ruslank100 and mado0211 like this.
  6. Barritico

    Barritico

    Joined:
    Jun 9, 2017
    Posts:
    372

    I am suffering from this problem.
    In the compliant version, the CPU is in 50-60% usage.
    The noise and temperature (with the risk involved) are very annoying.

    There are developers who do not give importance to this, but it seems a very serious problem. The image is that the final game is badly thought.

    I use VSYNC but I have to use EVERY SECOND so that the CPU usage is 20-30%.

    Honestly, it seems like a huge Unity problem that I should face in some way. Except if Unity has focused on Mobile and has set aside the desktop.
     
  7. Sixbraker

    Sixbraker

    Joined:
    May 20, 2017
    Posts:
    8
    thank you. this solved my issue so much. my CPU under Stats was running around 50-60 ms and it was so laggy. The minute I plugged this code on my Start() function my editor game run so much smoother!
     
  8. milleralex0827

    milleralex0827

    Joined:
    Apr 22, 2021
    Posts:
    2
    could someone explain how to do this step by step? Super new to Unity and I tried building my project via WebGL and I had 100% CPU usage
     
  9. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    To update things a bit, with the introduction of tech like G-sync, it can be appropriate to use targetFrameRate, however it should be an option and it should never be hard-coded as 60. High framerate monitors are also increasingly in use now.

    --Eric
     
  10. wannaMakeAGame

    wannaMakeAGame

    Joined:
    Dec 7, 2020
    Posts:
    47
    When in play mode, my cpu usage goes over hundred percent, computer gets heated very fast, so i cant stay in play mode for a long time. Yes, setting a target frame rate kinda solves the problem, but even with 60 frame rate, 75 percent cpu is still very high i guess. If you dont set a limit sometimes it reaches 200. Is 200%cpu usage normal, it gives like 250 frame rate then, but I feel like it is really problematic, maybe I do something wrong with my drivers or something, right?
    For example while watching a film it is almost no gpu and cpu usage, but even in an empty scene in unity, cpu usage is easily over hundred in play mode, what can be the problem?
     
    X2DGmDev likes this.
  11. Beefnjelly

    Beefnjelly

    Joined:
    May 10, 2021
    Posts:
    5
    task.PNG I also have a problem, as you can see.
     
    wmadwand likes this.
  12. DerDicke

    DerDicke

    Joined:
    Jun 30, 2015
    Posts:
    291
    Does Unity Editor restrict CPU usage in 2023?
    Just asking because my game is clearly GPU bound (on my machine, ok CPU, weak GPU) and in Editor, in some situations GPU usage falls to 70% and CPU usage caps at 50% (in these situations), while in Build GPU is always around 100% no matter what (with +20% framerate).
    Just wanne know so I can take action in case of optimizing for weak GPUs.

    Btw, all CPU Cores are pretty much balanced with I assume clipping and other rendering setup (doesn't happen much else atm), which I appreciate very much.
     
    X2DGmDev likes this.