Create custom scalers to automatically adjust quality settings based on device performance.
Custom scalers allow you to extend the Adaptive Performance system with your own logic for controlling quality settings. For more information about scalers, refer to Modifying asset quality with scalers.
There are two ways to create custom scalers:
The method you choose determines how you configure the scaler and how it applies at runtime.
Important: These two workflows are mutually exclusive. If you add a custom scaler through the Editor interface, Unity disables the automatic runtime scan for script-only scalers. Choose one method for your project.
Create a ScriptableObject asset from your scaler script to configure the scaler’s properties directly in the Editor for each scaler profile.
To add a custom scaler in the Editor, you need to create the custom scaler script and add the scaler asset to a scaler profile.
To create the script:
AdaptivePerformanceScaler.CreateAssetMenu attribute to the class. This exposes the script in the Assets > Create menu.OnLevel, OnEnabled, and OnDisabled.To add and configure the asset:
CreateAssetMenu attribute. This creates a new scaler asset file in your Project window.After you complete these steps, you have a scaler asset in your Project window that you can add to any scaler profile and configure independently.
After you add the asset, be aware of the following behavior:
This example demonstrates a script for the Editor interface workflow. All settings are configured in the Editor.
using UnityEngine;
using UnityEngine.AdaptivePerformance;
// This attribute allows you to create an asset from this script
// via Assets > Create > Scriptable Objects > Texture Quality Scaler UI.
[CreateAssetMenu(fileName = "TextureQualityScaler_UI", menuName = "Scriptable Objects/Texture Quality Scaler UI")]
public class TextureQualityScalerUI : AdaptivePerformanceScaler
{
private int m_DefaultTextureLimit;
protected override void OnEnabled()
{
// Store the original texture quality setting when the scaler is enabled.
m_DefaultTextureLimit = QualitySettings.globalTextureMipmapLimit;
}
protected override void OnDisabled()
{
// Restore the original setting when the scaler is disabled.
m_DefaultTextureLimit = QualitySettings.globalTextureMipmapLimit;
}
// This method is called when the performance level changes.
protected override void OnLevel()
{
// The base class calculates the new `Scale` value based on the current performance level.
// Apply the new scale to the global mipmap limit.
// A higher scale (better quality) maps to a lower mipmap limit (better quality).
if (ScaleChanged())
{
// Adjust the global texture mipmap limit based on the new scale.
Debug.Log($"TextureQualityScalerUI new scale: {Scale}");
QualitySettings.globalTextureMipmapLimit = (int)MaxBound - ((int)(MaxBound * Scale));
}
}
}
In this workflow, you define the scaler’s settings directly in the script. At runtime, Unity scans your project for any scripts that inherit from AdaptivePerformanceScaler and adds them automatically. The settings defined in the script apply globally to all scaler profiles.
Each scaler stores separate settings for each operation mode. Define settings for both normal mode and battery mode, then apply them in Awake:
ApplyDefaultSetting.ApplyBatteryModeSetting.If you don’t apply battery mode settings, the scaler uses empty settings and stays in non-active state while the application is in battery mode.
To create a script-only custom scaler:
AdaptivePerformanceScaler.AdaptivePerformanceScalerSettingsBase name.After you complete these steps, you have a custom scaler script in your project. When you enter Play mode, Adaptive Performance automatically detects and applies this scaler, provided you haven’t added any scalers using the Editor interface.
This example defines separate settings for normal mode and battery mode in the script.
using UnityEngine;
using UnityEngine.AdaptivePerformance;
public class TextureQualityScalerScriptOnly : AdaptivePerformanceScaler
{
// Settings used in normal mode.
private AdaptivePerformanceScalerSettingsBase m_NormalModeSettings = new AdaptivePerformanceScalerSettingsBase
{
// This name must exactly match the class name.
name = "TextureQualityScalerScriptOnly",
enabled = false,
scale = 1.0f,
visualImpact = ScalerVisualImpact.High,
target = ScalerTarget.GPU,
minBound = 0,
maxBound = 4,
maxLevel = 4
};
// Settings used in battery mode. Tune these to push quality lower to save power.
private AdaptivePerformanceScalerSettingsBase m_BatteryModeSettings = new AdaptivePerformanceScalerSettingsBase
{
name = "TextureQualityScalerScriptOnly",
enabled = true,
scale = 1.0f,
visualImpact = ScalerVisualImpact.High,
target = ScalerTarget.GPU,
minBound = 0,
maxBound = 4,
maxLevel = 4
};
private int m_DefaultTextureLimit;
protected override void Awake()
{
base.Awake();
// Apply the settings for each operation mode.
ApplyDefaultSetting(m_NormalModeSettings);
ApplyBatteryModeSetting(m_BatteryModeSettings);
}
protected override void OnEnabled()
{
m_DefaultTextureLimit = QualitySettings.globalTextureMipmapLimit;
}
protected override void OnDisabled()
{
QualitySettings.globalTextureMipmapLimit = m_DefaultTextureLimit;
}
protected override void OnLevel()
{
if (ScaleChanged())
{
Debug.Log($"TextureQualityScalerScriptOnly new scale: {Scale}");
QualitySettings.globalTextureMipmapLimit = (int)MaxBound - ((int)(MaxBound * Scale));
}
}
}