What happens if you have an empty container object with a script on it but no mesh and it contains other game objects with meshes and you just want to show and hide the container object.
Can’t use SetActive because then it wont respond to any events, you can’t use your method because it does not have a mesh and I can’t use localScale(0,0,0) because then it wont respond to mouse events.
I ended up solving it with an overrideable DoShow(bool bShow) function but this is a this is a bit of bloody pain with Unity - there needs to be one consistent way of showing and hiding objects while leaving them responsive!
if its a container object then you can use GetComponentsInChildren() and loop through the array it returns and toggle the scripts enable property. this is by far the least intrusive way to toggle gameobject’s visiblity and keep them enabled.
Monobehaviours actually do respond to events just fine even when disabled. OnCollision and OnTrigger calls do infact still be called. and any event (Event, UnityEvent, Delegate, or otherwise) you subscribe to can still trigger a disabled object just fine.
It just doesn’t call the Awake/Start/Update/FixedUpdate, which is intended, Theres a difference.
Surely that would just be adding unnecessary CPU overhead.
It would be ideal if an empty gameobject had a show/hide flag (that did not disable Start, Update and Awake) and the unity engine just halted rendering all child objects before it even started.
make it work, then make it right, then make it fast.
you’d find that working in this order you’ll discover that you usually won’t have to worry about performance until it matters.
actually try it first, when performance does fail, its very likely not because of this.
calling Find() in update… thats a performance issue.
spawning hundreds of projectiles per second… thats a performance issue
decompressing images for a 360 VR in realtime… thats a performance issue…
but calling GetComponentsInChildren on mouse click… not even a drop in the bucket.
OK, well even if it is not a noticeable performance issue it would still be ‘nice’ to have the a fore mentioned feature even if it just saves you some additional typing for a longer function.
Yeah but the problem was that my empty container game object did not have a renderer - it has a script that does some stuff but no visible component. I just want to show and hide the container and not have to iterate through all the children.
I want the container object to act as the visibility controller for all the children regardless of whether or not it has a renderer.
What this means at present is that I cannot have a single standard Show/Hide function in my base class - I have to override it and change the implementation depending on whether the game object to which the script is attached has a renderer on it also or whether or not it should accept mouse input while invisible.