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 windowA window that shows the contents of your Assets folder (Project tab) More info
See in Glossary 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 scriptsA piece of code that allows you to create your own Components, trigger game events, modify Component properties over time and respond to user input in any way you like. More info
See in Glossary that inherit from AdaptivePerformanceScaler and adds them automatically. The settings defined in the script apply globally to all scaler profiles.
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 includes all settings defined in the script.
using UnityEngine;
using UnityEngine.AdaptivePerformance;
public class TextureQualityScalerScriptOnly : AdaptivePerformanceScaler
{
// Define the default settings for the scaler.
private AdaptivePerformanceScalerSettingsBase m_AdaptiveTextureQualityScaler = 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
};
private int m_DefaultTextureLimit;
protected override void Awake()
{
base.Awake();
// Apply the default settings defined above.
ApplyDefaultSetting(m_AdaptiveTextureQualityScaler);
}
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));
}
}
}