Game.Rendering.VolumeHelper
Assembly: Assembly-CSharp
Namespace: Game.Rendering
Type: public static class VolumeHelper
Base: System.Object
Summary:
Utility helper for creating, managing and destroying Unity HDRP Volume objects and their profiles/components in Cities: Skylines 2. Provides convenience routines for creating Volume GameObjects under a dedicated ordered spawner, creating non-persistent VolumeProfiles, tracking created Volumes for cleanup, and ensuring VolumeComponents that use quality settings are initialized with a default quality value.
Fields
-
public const int kQualityVolumePriority
Default priority constant intended for quality-related volumes (value 100). Use when creating volumes that should be prioritized above general game volumes but below override volumes. -
public const int kGameVolumePriority
Default priority constant intended for general game volumes (value 50). Use for standard game-level volumes. -
public const int kOverrideVolumePriority
High priority constant for override volumes (value 2000). Use for volumes that must override other settings. -
private const string kSectionName
Internal string used as the ordered game object spawner section name ("======Volumes======"). Volumes are spawned under this ordered section to keep the scene hierarchy organized. -
private static List<Volume> m_Volumes
Internal list tracking created Volume instances so they can be disposed/destroyed later by Dispose(). This list is updated when volumes are created and when they are destroyed.
Properties
- (none)
Constructors
- (none — static utility class)
Methods
-
public static void Dispose()
Destroys all tracked Volume instances in reverse order and clears them from internal tracking. Internally calls DestroyVolume on each entry; used to clean up created volumes and their profiles (invokes CoreUtils.Destroy on profiles and GameObjects). -
private static VolumeProfile CreateVolumeProfile(string overrideName)
Creates a new non-persistent VolumeProfile ScriptableObject. The profile is named using the provided overrideName + "Profile" and marked with HideFlags.DontSave so it is not saved with scenes. -
public static Volume CreateVolume(string name, int priority)
Creates a Volume GameObject under the ordered section named by kSectionName via OrderedGameObjectSpawner.Get(...).Create(name). The GameObject and its profile are marked DontSave, the Volume.priority is set to the provided value, a new VolumeProfile is created and assigned to sharedProfile, and the Volume is added to m_Volumes for tracking. Returns the created Volume. -
public static void DestroyVolume(Volume volume)
Removes the given Volume from internal tracking. If the Volume has a sharedProfile, it is destroyed via CoreUtils.Destroy. The Volume's GameObject is also destroyed via CoreUtils.Destroy. Safe to call for cleanup of individual volumes. -
public static void GetOrCreateVolumeComponent<PT>(Volume volume, ref PT component) where PT : VolumeComponent
Convenience overload that forwards to the profile-based overload using volume.profileRef. -
public static void GetOrCreateVolumeComponent<PT>(VolumeProfile profile, ref PT component) where PT : VolumeComponent
Ensures the specified VolumeComponent type exists on the provided VolumeProfile. If the component reference is null and the profile does not already contain the component, the method adds it (profile.Add()). If the created component implements VolumeComponentWithQuality, the method sets its quality value by calling quality.Override(3) (initializes a reasonable default quality level).
Usage Example
using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.Rendering.HighDefinition;
// Create a persistent volume in the ordered "Volumes" section.
Volume v = VolumeHelper.CreateVolume("MyCustomVolume", VolumeHelper.kGameVolumePriority);
// Get or create a custom VolumeComponent (replace MyVolumeComponent with your type)
MyVolumeComponent myComp = null;
VolumeHelper.GetOrCreateVolumeComponent<MyVolumeComponent>(v, ref myComp);
// Optionally change priority or adjust the profile/component as needed
v.priority = VolumeHelper.kOverrideVolumePriority;
// ... configure myComp fields ...
// When shutting down or unloading the mod, clean up created volumes:
VolumeHelper.Dispose();
Notes: - Created VolumeProfiles and GameObjects are marked HideFlags.DontSave so they won't be saved with scenes; they should be explicitly destroyed to avoid leaks (Dispose/DestroyVolume). - The helper relies on OrderedGameObjectSpawner and CoreUtils (HDRP/Unity utilities) available in the Cities: Skylines 2 environment.