Execute an operation each X frames on Unity Update() Method

Often you want the ease of using Unity’s Update() method, but want to avoid performing a heavy operation on all frames when that is not always necessary?

Here’s a golden tip!

void Update()
{
    if (Time.frameCount % 10 == 0)
   {
      //This will be only executed each 10 frames
   }
}

You can change the value 10 to the interval of frames that you want to this code block to be executed.

Did you already know this feature? I use it in several of my games to avoid performing operations on all frames.


Until next time, peace! 🖖

Leave a Reply

Your email address will not be published. Required fields are marked *