I’m curious about this, do you guys prefer to deactivate entire GameObjects, let’s say a text panel containing buttons, images etc which is going to be show/hide several times OR just move it outside camera bounds (hide it from the camera), which one is best for performance?
Rarely does performance enter into this kind of calculation. Perhaps, but far more often the choice is just for convenience or to better understand and/or model the problem.
I would NOT do this ever. In fact, don’t ever set any scales to zero, even one axis.
The reason: a lot of code that auto-calculates layout (such as what is in the UnityEngine.UI hierarchy) will malfunction, since it does positioning and layout based on scale values, and if it has to divide by the size of something in order to lay it out, if you set that scale to zero, well, you can imagine the issues.
A common source of inadvertent zero scaling is when you use this construct:
// NEVER do this:
transform.localScale = new Vector2( Width, Height);
Looks innocuous but you just set the z scale to zero with that. For one, TextMeshPRO will completely lose its layout mind with this, and all kinds of bizarre stuff will happen: black lettering, missing lettering, garbled fonts, you name it.
Instead, always do this:
transform.localScale = new Vector3( Width, Height, 1);
when it is a scale.
You can delete/reinstantiate chunks of UI, you can disable/enable, you can just layer them differently (sorting order or hierarchy), you can physically move them away offscreen, pretty much anything you like.
In fact, it’s not uncommon to do all these things.
Thanks for your contribution! so the reason i’m asking this (appart from the performance question) is to keep coroutines working, if i disable the parent component to “hide” it all coroutines from it and it’s children are stopped.
So i think i’ll disable when i don’t need coroutines and hide it from camera when i still need coroutines to keep working
Another solution for this is a coroutine runner, a separate MonoBehavior that runs all your coroutines.
HOWEVER, that does require higher awareness, since if you destroy an object when there is a coroutine manipulating it, the coroutine will happily just keep generating errors by touching the destroyed object.