Reducing the number of active objects by making objects inactive whenever possible
Optimization principal 1: Minimize the number of active and enabled objects in a scene.
Sometimes, we may not want to completely remove an object, but it is possible to go one step further than disabling a scripted component by making the parent GameObject
that contains the scripted component inactive
. This is just like deselecting the checkbox next to the GameObject
in the Inspector, as shown in the following screenshot:
How to do it...
To reduce computer processing workload requirements by making an object inactive when it becomes invisible, follow these steps:
- Copy the previous recipe.
- Remove the scripted component
DisableWhenNotVisible
from your Cube, and instead, add the following C# script classInactiveWhenNotVisible
to Cube:using UnityEngine; using System.Collections; using UnityEngine.UI; public class InactiveWhenNotVisible : MonoBehaviour { // button action public void BUTTON_ACTION_MakeActive...