New Project > Add a single script that runs Update() > CPU usage 100% >what is going on here??

Hi, I started a new project, added some UI, and now wanted to add TAB key navigation since this feature has been missing from Unity for almost a decade now (lmao).

So I added a new script to the project and added it to a gameObject:

using UnityEngine;
using UnityEngine.UI;
using UnityEngine.EventSystems;


public class UI_TabKeyNavigation : MonoBehaviour
{
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.Tab))
        {
            GameObject c = EventSystem.current.currentSelectedGameObject;
            if (c == null) { return; }

            Selectable s = c.GetComponent<Selectable>();
            if (s == null) { return; }

            Selectable jump = Input.GetKey(KeyCode.LeftShift)
                ? s.FindSelectableOnUp() : s.FindSelectableOnDown();
            if (jump != null) { jump.Select(); }
        }
    }

}

Enter PlayMode to test it…
All of a sudden my fans go on MAX.
Check CPU usage in Task Manager > its freaking 100%???
Wat is going on here Unity??

This is literally the whole project, some UI, 8 elements total. And that single script. There is nothing else.

VSync

Is that related to MonoBehaviour.Update()?

If Vsync is disabled, it means your computer is working as fast as it possibly can (100%) in order to render as many frames as possible for no good reason.

Enable Vsync and framerate is a steady 60 fps, disable it and it may be 600 or more, with only every tenth rendered image actually displayed.

For a build, vsync is enabled via Quality settings. It may still be overridden on the driver level however.

This fixed it. Ive been working in Unity for years now and never had this problem before though, but good to know now! Thanks.

To be precise Vsync’s decrease of the CPU is a side effect of what’s actually happening: the GPU trying to make as many frames as possible. If the CPU is sufficiently powerful to keep the GPU fed with data turning it on can reduce the CPU load, but if the CPU is too weak to feed the GPU then it’s going to stay at 100%.

Your monitor is somewhat important here too as even budget displays often have a higher refresh rate (eg 144Hz) which means that the CPU has to work up to 2.4x as hard (60Hz = 16.67ms per frame, 144Hz = 6.94ms per frame).

The editor interaction mode is also relevant for controlling the frame rate of the editor.

"Interaction Mode,After one frame finishes, the Editor waits up to the specified amount of time before the next frame begins.

This allows you to throttle Editor performance, and reduce consumption of CPU resources and power.

For example, if you want to test the Editor’s performance, set this property to No Throttling."