- Home /
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.
Answer by tormentoarmagedoom · May 22, 2019 at 11:54 AM
Hello.
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!
Bye!
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
How to make boolean be true for x amount of seconds? 2 Answers
How to access the Boolean for one object? 1 Answer
How to Set Application.isFocused? 1 Answer