4.2.8 Use OnBecameVisible()and OnBecomeInvisible() callbacks

If you use the callbacks MonoBehaviour.OnBecameVisible() and MonoBehaviour.OnBecameInvisible(), Unity notifies your scripts when their associated game objects moves in or out of a camera frustum. Your application can then act accordingly.

You can use OnBecameVisible() and OnBecameInvisible() to optimize the rendering process, for example, rendering reflections on a pool with a second camera and render targets.
This involves rendering geometry and combining textures off screen before rendering to the final screen surface. This technique is relatively expensive so it is only used when it is necessary. You are only required to render a reflection when it is visible. That is when:
These conditions are checked with the OnBecameVisible() and OnBecameInvisible() callbacks from the reflective surface:
void OnBecomeVisible()
{
	enabled = true;
}

void OnBecomeInvisible()
{
	enabled = false;
}
Even with these checks in place there can still be times when a reflection might be rendered off screen even though it is not visible onscreen. To avoid this you can add another condition:
For example, the camera must be inside the room of the reflective surface:
void OnBecomeVisible()
{
	if (inside == false)
	{
		return;
	}
	enabled = true;
}

void OnBecomeInvisible()
{
	if (inside == false)
	{
		return;
	}
	enabled = false;
}

void OnTriggerEnter()
{
	inside = true;
}

void OnTriggerExit()
{
	inside = false;
}
These conditions restrict the rendering of reflections to specific areas of the game. This means you can add effects in other, less compute intensive areas of the game.
Non-ConfidentialPDF file icon PDF versionARM 100140_0201_00_en
Copyright © 2014, 2015 ARM. All rights reserved.