- Home /
Is there a hidden cost of enabling/disabling something that is already in that state?
If I iterate through gameObjects or components and all are disabled, and I tell each one to disable, is there a hidden cost in resetting the state even though it already was in that state, or will the command just be ignored?
So basically should I be checking if something is already in a disable or enable before telling it to be in a state? I mean in order to avoid telling it to enable when it already is or disable when it already is.
Answer by tanoshimi · Feb 06, 2016 at 04:23 PM
The only way to answer that question is to use the profiler.
I suspect there will be no noticeable difference between: "Check if object is enabled, then only disable it if so" and "Disable object whether it is enabled or not".
A better solution would of course to only call your Disable() command on objects which you know are enabled in the first place, although the performance difference will still probably only be slight.
Basically, unless you are actually observing a performance bottleneck as a result of this specific bit of code, it's a case of premature optimisation and you should just ignore it and move on :)
Your answer
Follow this Question
Related Questions
Enable Child Component C# 1 Answer
Distribute terrain in zones 3 Answers
Speed and efficiency of enabling/disabling component? 1 Answer
Multiple Cars not working 1 Answer
Reference Variables and Drag-And-Drop 0 Answers