Will C# in Unity validate/check the state of a boolean every frame or will it just remember the state and change its state when needed?

I was wondering if u have a lot of if statements that aren’t necessary constantly changing will the program go through all the if statements every time to check their states or will it remember the states (of the booleans in the if statements) so the program knows it doesn’t need to check the if statements of those booleans that haven’t changed ‘yet’? Or will it remember the value of those booleans but still going through al the if statements to check it :)? Sry for my bad English.


Depends, but as normal, if you have this if sentences in your Update() , code will go line by line all frames, so yes, it will be checking the state every frame.

But there are multiple ways to prevent that.

For example, Corutines (you can make each frame to check only 1 of the ifs for example). Check this tutorial

You can also use delegates (look this post showing how)…

And for sure anything else you can imagine!