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.

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 :slight_smile: