Only Disable One Update on a Script
Say I have a script with two loops:
void Update() {
Debug.Log("Update");
}
void FixedUpdate() {
Debug.Log("FixedUpdate");
}
If I wanted to disable the script from looping, I would use:
this.enabled = false;
But what if I only wanted to disable either the FixedUpdate()? or Update()? I can only have both, or none.
So is there a way to disable one of the loops, without having to write something like this?
bool update, fixedUpdate;
void Update() {
if(update)
Debug.Log("Update");
}
void FixedUpdate() {
if(fixedUpdate)
Debug.Log("Fixed Update");
}
If I did that, I'm still calling the Update() and FixedUpdate(), which is pretty wasteful.
Any ways around this?
Thanks.
Not sure if this is possible. Why do you need to do it? $$anonymous$$aybe there is another solution\program$$anonymous$$g pattern to what you need.
I don't really need to do it. I'm mostly curious. It would be very useful information for the future.
One solution then might be to have an empty game object and add two objects to it one with a script that calls Update and the other with a script that calls FixedUpdate, then you could enable/disable as you wished.
Answer by skillbow · Jan 29, 2017 at 04:04 PM
One solution then might be to have an empty game object and add two objects to it one with a script that calls Update and the other with a script that calls FixedUpdate, then you could enable/disable as you wished.
Your answer
Follow this Question
Related Questions
Updating Unity or not when working on a project? 0 Answers
Instantiation Breaks Update Function 0 Answers