How to make a function triggered when you activate/deactivate a GameObject

Hi everyone.

I am making a game and want to use only one scene, as the continuous creation and destruction of objects is quite expensive and may even cause memory errors (correct me if I am wrong, but that’s what they told me in college)

So, to emulate the desired behaviour, I made this:
Scene → Empty GameObject
GameObjects in a Scene → Children of the scene GO
Scene Change → Activate and deactivate Scene GO (and by extension all their children)

The thing is, I want to know if it is possible to make a function that is triggered every time you activate a GameObject (what in a normal architecture would be done by the Start function)

Thanks in advanced and sorry for bad English :stuck_out_tongue:

It is possible, check out OnEnable and OnDisable.

Check out this link for reference on the order of MonoBehaviour callbacks: http://docs.unity3d.com/Manual/ExecutionOrder.html

1 Like

Thanks man. That’s exactly what wanted :slight_smile:

1 Like