Hello!
I’m new to Unity, C# and VR development, and I come from a web background.
I’m designing a World Space UI Canvas and working with VRTK to interact with the UI elements using ray casting. I simply need to be able to toggle the visibility of a Game Object based on "click"s on another Game Object (a UI Button).
Very often, I find myself checking to see if a Game Object has been attached to the scene before I query it and work with it. So my code is sprinkled with if (myGameObject != null) { /* do something */ }
Is this an anti-pattern? Is there any equivalent to the Web’s beloved onload
, domContentLoaded
or $(document).ready /* jQuery */
in Unity + C# land? I simply need to know deterministically if the Game Objects I need have been attached.
Thank you.