Fundamental question about Update()

Sorry for the incredibly basic question, but it’s something I’ve been wondering about that I’d like to ask - (in regards to performance optimization and basic understanding that I’ve missed along the way)

Given something as simple as this:

    void Update()
        if (Input.GetKey("escape"))

Does C# or the compiler (or whatever, feel free to correct that language) check to see if the if statement is valid every frame, or does it just skip this and treat it like an event call or something?

In other words - if your game is just running idle - play button on with no input happening - you’re just staring at the screen - what’s happening behind the scenes? Is the engine checking this if statement every frame with everything in Input or is it more like it’s just waiting for Input to send a message or something?

Thanks again for any clarification, hopefully someone finds some enjoyment in trying to answer this for me : )

The current Input system of Unity (soon-to-be deprecated) makes you poll for input every frame. It is not event based, so basically, yes, your if condition will check every frame whether or not the escape key is pressed.

A new Input system is currently under development and takes the form of a preview package in the package manager. A forum thread is open to check for the news about it.

The tutorial of Brackeys will give you an quick-start to the new Input system, but again, this new package is under development, so I would not advise to use it for complex games meant for the general public.