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. Voting for the Unity Awards are OPEN! We’re looking to celebrate creators across games, industry, film, and many more categories. Cast your vote now for all categories
    Dismiss Notice
  3. Dismiss Notice

How to deal with high CPU load on slow force change ?

Discussion in 'Scripting' started by u_rs, Jan 21, 2018.

  1. u_rs

    u_rs

    Joined:
    Jan 5, 2016
    Posts:
    147
    I tried to apply force to object, so that it soar in the air.
    Code (CSharp):
    1. void FixedUpdate () {
    2.         rb.AddForce(Vector3.up * thrust);
    3.     }
    Tried to change force a very little bit, so it would move very slow up or down. And when I was doing that I started to hear my computer's fan. I saw that it's heavy for CPU. And I think that it's gonna be even harder to bear for smartphone. What would you recommend ?
     
  2. TaleOf4Gamers

    TaleOf4Gamers

    Joined:
    Nov 15, 2013
    Posts:
    825
    I wouldnt expect this to be that bad TBH. 50 times a second (by default) is certainly quite a bit but I wouldnt expect it to bring a PC to its knees or anything. Did you check the profiler? It will show you exactly what is going on.
     
  3. u_rs

    u_rs

    Joined:
    Jan 5, 2016
    Posts:
    147
    Any comments on my profiler's screenshot ?
     

    Attached Files:

  4. Fido789

    Fido789

    Joined:
    Feb 26, 2013
    Posts:
    343
    I see nothing suspicious. It was probably just a coincidence caused by something else. Is it reproductible (repeatable)? EDIT: If it is reproductible, you should look to the task manager, if it really burden CPU so much.
     
    Last edited: Jan 21, 2018
  5. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    Most of your time seems to be spent idling waiting for VSync. You've got plenty of CPU time up your sleeve. I wouldn't worry about it.
     
  6. methos5k

    methos5k

    Joined:
    Aug 3, 2015
    Posts:
    8,712
    Just a thought: You might have noticed a fan speed change just from Unity in general. I mean if it was in a very low state before, the difference could be noticeable. I have no idea, but I certainly know moving 1 object with that script won't be causing your pc to go crazy on its own :)
     
  7. u_rs

    u_rs

    Joined:
    Jan 5, 2016
    Posts:
    147
    It is repeateble. You're right, it seems that Unity always uses CPU a lot - till 55% while editor is in idle. It seems that when object moving it takes a little bit more of CPU, so fan starts work harder. It is Linux's Unity-2017.3.0p2.
     
  8. u_rs

    u_rs

    Joined:
    Jan 5, 2016
    Posts:
    147
    I restarted Unity and it's got better. I think it's alright now. Thanks.
     
  9. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    You should look up "Unity Profiler".