- Home /
Stopping FixedUpdate
In my lockstep multiplayer game, I run specific simulations in FixedUpdate that need to be stopped under certain circumstances (I.e. in case of high latency). Normally, I'd use Time.timeScale = 0 but this is not possible because my coroutines would be affected, something that I need to run continuously. Can I stop FixedUpdate without using Time.timeScale? Would there be any glitches if I set Time.fixedDeltaTime to Mathf.infinity?
Could you not just pause some of the coroutines while allowing the rest to continue?
Answer by jpthek9 · Jan 08, 2015 at 04:41 PM
The solution is using a boolean to control FixeDUpdate, something very controllable by me. Then I can use a coroutine or invoke repeating to keep the package sends.
Hi jpthek9, I need to run a specific amount of fixed updates, would you $$anonymous$$d elaborating on what you mean by "using a boolean to control FixeDUpdate"?
Answer by 3dmihai · Aug 30, 2016 at 10:20 AM
You can use a variable to check if a certain is met and execute the code. If the condition is not met - this is the case when you don't want to execute the code - set the variable to false. For example:
// ...
public static bool shouldExecute;
// ...
void FixedUpdate() {
if (shouldExecute == true) {
// your code within FixedUpdate
}
}
This way you can access shouldExecute variable from anywhere like this: ClassName.shouldExecute and set the value to true or false. I hope this helps.
Thanks for the response, but I need to control the amount of physics steps, its not about my code...
You do not have to write == true
in the if statement. Just write the var
or !var
public static bool shouldExecute;
// ...
void FixedUpdate() {
if (shouldExecute) {
// your code within FixedUpdate
}
}
Your answer
Follow this Question
Related Questions
Pause game on Start doesn't quite work 1 Answer
Timescale wont work 0 Answers