# 5. Runtime Switching, Profiling and Pitfalls Part of [[Scalability and Quality Tiers]]. Back: [[4. Occlusion Culling in URP]]. > [!warning] Code not compiled in Unity > `QualityTierSwitcher` was type-checked against Unity 6000.5.8f1 (`QualitySettings` in that Editor's UnityEngine.CoreModule). It has not been run in Play Mode or on a device. Mid-game Quality switches were not verified. ## 5.1 The official switch ```csharp QualitySettings.SetQualityLevel(index, applyExpensiveChanges); ``` - `index` is the index in **Project Settings > Quality**, in list order (`QualitySettings.names` is the official name array). - `applyExpensiveChanges`: `true` applies expensive changes (the Manual calls out anti-aliasing as the example) immediately. `false` defers them until they are cheap to apply (typically a later level load). For a settings-menu "apply now" button, pass `true`. For a boot-time pick before the first scene, `true` is also fine. Read the current index with `QualitySettings.GetQualityLevel()`. Do not cache a `UniversalRenderPipelineAsset` reference across a switch; ask for the current pipeline asset again if you must read `renderScale`. ## 5.2 QualityTierSwitcher Drop this on a bootstrap object, or call it from the Quality dropdown in [[Menus, Pause and Settings Flow]]. It does not touch URP APIs, so it does not depend on `ENABLE_UPSCALER_FRAMEWORK` or `upscalingFilter` vs `upscalerName`. ```csharp using System; using UnityEngine; /// <summary> /// Switches Unity Quality levels by index or by the level's official name. /// Author one URP asset per level; this class only asks QualitySettings /// to swap the active level. /// </summary> public sealed class QualityTierSwitcher : MonoBehaviour { [SerializeField] bool applyExpensiveChanges = true; public event Action<int> QualityChanged; public string[] LevelNames => QualitySettings.names; public int CurrentIndex => QualitySettings.GetQualityLevel(); public string CurrentName { get { var names = QualitySettings.names; var i = CurrentIndex; return names != null && i >= 0 && i < names.Length ? names[i] : string.Empty; } } public void ApplyIndex(int index) { var names = QualitySettings.names; if (names == null || index < 0 || index >= names.Length) { Debug.LogWarning(quot;QualityTierSwitcher: index {index} is outside QualitySettings.names."); return; } QualitySettings.SetQualityLevel(index, applyExpensiveChanges); QualityChanged?.Invoke(QualitySettings.GetQualityLevel()); } public bool ApplyName(string qualityLevelName) { if (string.IsNullOrEmpty(qualityLevelName)) return false; var names = QualitySettings.names; if (names == null) return false; for (var i = 0; i < names.Length; i++) { if (names[i] == qualityLevelName) { ApplyIndex(i); return true; } } Debug.LogWarning(quot;QualityTierSwitcher: no Quality level named '{qualityLevelName}'."); return false; } } ``` Populate a UI Toolkit dropdown from `LevelNames`. Persist the chosen name (not the index) in player settings so a reordered Quality list does not silently pick the wrong tier — the same "save a stable key" habit as [[High Scores, Saves and Player Stats]]. A first-run default can still use `QualitySettings.GetQualityLevel()` after you have set **platform defaults** in the Quality table (Quest Android -> `Quest`). ## 5.3 Profiling checklist Work through this once per Quality asset, in the Editor and on the target device. Use [[Profiling and Optimization]] and [[4. Frame Debugger and GPU]]. 1. Confirm the active Quality name and that the expected URP asset is current. 2. Record CPU and GPU frame time, and the render-target resolution (Render Scale is doing what you think). 3. Toggle STP vs Bilinear on a *copy* of the asset if you need an A/B; do not A/B by mutating the shipping asset from a debug menu if you can swap two Quality levels instead. 4. Confirm UI is native resolution (part 2) — a soft HUD usually means you scaled a screen-space camera, not that Render Scale is broken. 5. If Resident Drawer is on: Frame Debugger instanced batches, then an on/off CPU compare (part 3). 6. If GPU occlusion is on: hidden instances actually disappear (part 4). 7. On Quest: Graphics API is Vulkan if you relied on STP or the Resident Drawer; GLES is an automatic "those features are not your path." 8. Water / refraction: Opaque Texture off on the Quest asset unless a capture says you can afford it ([[2. Depth Fade with Scene Depth Difference]], [[6. Quest Cost and Quality Tiers]]). 9. Texture memory: ASTC and max sizes from [[3. Quest Texture Compression and Platform Overrides]] still dominate when upscaling is already reasonable. ## 5.4 Symptom table | Symptom | Check first | |---|---| | Quality dropdown does nothing visible | The Quality level still points at the *same* URP asset, or you changed the global Graphics asset instead of the per-level slot | | STP looks like bilinear, or is missing | GLES in the API list; no compute / SM 5.0; Dynamic Resolution on (unsupported with STP — use Render Scale) | | STP made Quest *worse* at scale 1.0 | Expected: STP stays on as TAA at scale 1.0. Lower Render Scale or switch the Quest asset to Bilinear | | Resident Drawer "on" but no instanced batches | `BatchRendererGroup Variants` not **Keep All**; renderer is Forward, not Forward+ / Deferred+; objects don't qualify and fell back silently | | GPU occlusion does nothing | Resident Drawer not actually drawing those meshes; feature enabled on a different URP asset than the active Quality | | Water vanished or refraction is black on Quest | Opaque Texture off (often intentional). See [[Water and Stylized Surfaces]] | | Mid-game switch hitch or leftover AA | Pass `applyExpensiveChanges: true` from an Apply button, or defer the switch to a loading screen | | `upscalingFilter` compile warning | Author the filter on the asset. The 17.5.0 property is obsolete when `ENABLE_UPSCALER_FRAMEWORK` is defined (hub) | | UI is blurry | A camera or canvas is not native; Render Scale officially does not scale UI | ## 5.5 What was not verified - Switching Quality mid-gameplay while a [[Timeline Advanced]] cutscene, a water refraction camera, or the GPU Resident Drawer is mid-frame. - The exact Android / Quest fallback when STP is selected on an unsupported GPU (official text: Automatic). - Running baked occlusion and GPU occlusion together on a mixed skinned / static scene. - VisionOS (Resident Drawer officially unsupported). Those belong in a project-specific capture, not in a guessed paragraph here.