# AdaptivePerformanceEnergyUsageExtensions

> Extension methods for IAdaptivePerformance related to energy-usage tracking.

## Definition

* **Type:** Class
* **Namespace:** [UnityEngine.AdaptivePerformance](/engine/6000.7/script-reference/unityengine/adaptiveperformance.md)
* **Assembly:** UnityEngine.AdaptivePerformanceModule

```csharp
public static class AdaptivePerformanceEnergyUsageExtensions
```

## Remarks

Call [AdaptivePerformanceEnergyUsageExtensions.EnergyUsageControl](/engine/6000.7/script-reference/unityengine/adaptiveperformance/adaptiveperformanceenergyusageextensions/energyusagecontrol.md) on an Adaptive Performance instance, such as [Holder.Instance](/engine/6000.7/script-reference/unityengine/adaptiveperformance/holder/instance.md), to reach the [IEnergyUsageControl](/engine/6000.7/script-reference/unityengine/adaptiveperformance/ienergyusagecontrol.md) interface that starts, resets, and stops energy-usage tracking.

The extension returns null when the active Adaptive Performance implementation doesn't provide energy-usage tracking at all, so check the result before you use it. A non-null result doesn't guarantee that the device itself can report energy: check [IEnergyUsageControl.EnergyUsageTrackingSupported](/engine/6000.7/script-reference/unityengine/adaptiveperformance/ienergyusagecontrol/energyusagetrackingsupported.md) as well.

Additional Resources: [IAdaptivePerformance](/engine/6000.7/script-reference/unityengine/adaptiveperformance/iadaptiveperformance.md), [IEnergyUsageControl](/engine/6000.7/script-reference/unityengine/adaptiveperformance/ienergyusagecontrol.md), [EnergyUsage](/engine/6000.7/script-reference/unityengine/adaptiveperformance/energyusage.md)

The following example acquires the energy-usage control, verifies that the device supports tracking, and tracks energy usage while a component is enabled.

## Examples

```csharp
using UnityEngine;
using UnityEngine.AdaptivePerformance;

public class EnergyUsageControlExample : MonoBehaviour
{
    IEnergyUsageControl energyUsageControl;

    void OnEnable()
    {
        IAdaptivePerformance adaptivePerformance = Holder.Instance;
        if (adaptivePerformance == null || !adaptivePerformance.Initialized)
            return;

        // The result is null when this Adaptive Performance implementation has no energy-usage tracking.
        energyUsageControl = adaptivePerformance.EnergyUsageControl();
        if (energyUsageControl == null)
        {
            Debug.Log("This Adaptive Performance implementation doesn't provide energy-usage tracking.");
            return;
        }

        // A non-null control doesn't guarantee that this device has usable power monitors.
        if (!energyUsageControl.EnergyUsageTrackingSupported)
        {
            Debug.Log("This device doesn't support energy-usage tracking.");
            return;
        }

        energyUsageControl.StartEnergyUsageTracking();
    }

    void OnDisable()
    {
        energyUsageControl?.StopEnergyUsageTracking();
    }
}
```

## Static Methods

| Method                                                                                                                                               | Description                                                                                                                                                  |
| ---------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| [EnergyUsageControl](/engine/6000.7/script-reference/unityengine/adaptiveperformance/adaptiveperformanceenergyusageextensions/energyusagecontrol.md) | Returns the energy-usage control for the given Adaptive Performance instance, or `null` if the active implementation does not support energy-usage tracking. |
