- Home /
Best practise time-based, repeating function calls: InvokeRepeating vs CustomSolution
I recently started work on a strategy game, which is very similar to games like ANNO, CIVILIZATION and SETTLERS.
For this I had to write a lot of functions which repeat each X seconds, e.g. worker requesting resources, taxes ticking every minute etc.
I solved this the following way:
private float repeatingIntervalInSeconds = 15;
private float timeSinceLastCall;
private void Update()
{
timeSinceLastCall += Time.deltaTime;
if(timeSinceLastCall >= repeatingIntervalInSeconds)
{
timeSinceLastCall -= repeatingIntervalInSeconds;
functionCall();
}
}
This however adds a lot of boilerplate. Now I read about InvokeRepeating but also read that it involves some overhead.
Is there another better way I overlooked or is it fine to use InvokeRepeating?
Your answer
Follow this Question
Related Questions
InvokeRepeating VS Coroutines [Performance] 1 Answer
Coroutine in place of InvokeRepeating in need of start at time parameter 1 Answer
Pause GameLoop with Pause Button 1 Answer
How can I get my platforms to randomly appear when not activated by button 1 Answer
convert timer from update() to coroutine or invokerepeating 0 Answers