Question: How do you change the skybox in Unity HDRP?


To change the skybox in Unity when using the High Definition Render Pipeline (HDRP), you need to modify the settings in your scene's Volume. Here are the steps:

  1. Create or Select a Volume: You can use an existing Volume in your scene or create a new one by going to GameObject > Volume and adding a Global Volume for scene-wide effects, or a Local Volume for more localized changes.

  2. Add the Sky and Fog Volume Override: If your Volume does not already have a Sky and Fog Volume component, add it by clicking "Add Override" and selecting Sky > Visual Environment.

  3. Set the Sky Type: In the Visual Environment override, set the Type to HDRI Sky.

  4. Add the HDRI Sky Override: Click on "Add Override" again, and this time select Sky > HDRI Sky.

  5. Assign Your HDR Skybox Material: Within the added HDRI Sky section, drag and drop your HDR skybox material into the HDRI Sky field. You can create an HDRI skybox material by right-clicking in the Project window, navigating to Create > Material, then changing the Shader of the new material to HDRP/Sky/HDRISky.

  6. Adjust Intensity and Exposure (if necessary): Within the HDRI Sky section, you can also adjust properties like Rotation, Exposure, and Multiplier to fine-tune the appearance of your sky.

  7. Save Changes: Ensure that the Volume is active and has a profile assigned so that the changes take effect.

Here's an example of code that changes the HDRI Sky dynamically:

using UnityEngine; using UnityEngine.Rendering.HighDefinition; using UnityEngine.Rendering; public class ChangeSkyboxHDRP : MonoBehaviour { public Cubemap hdriTexture; // Assign the HDRI cubemap in the inspector void Start() { // Get or Add the Volume component Volume volume = gameObject.GetComponent<Volume>() ?? gameObject.AddComponent<Volume>(); // Ensure the Volume has a Profile if (volume.profile == null) volume.profile = ScriptableObject.CreateInstance<VolumeProfile>(); // Find or Add the VisualEnvironment and HDRISky VisualEnvironment visualEnv; HDRISky hdriSky; if (!volume.profile.TryGet(out visualEnv)) visualEnv = volume.profile.Add<VisualEnvironment>(false); if (!volume.profile.TryGet(out hdriSky)) hdriSky = volume.profile.Add<HDRISky>(false); // Change the sky type to HDRI Sky visualEnv.skyType.value = (int)SkyType.HDRI; // Change the HDRISky component's texture and intensity hdriSky.hdriSky.value = hdriTexture; hdriSky.exposure.value = 1f; // Example exposure value hdriSky.multiplier.value = 1f; // Example intensity multiplier // Enable Overrides visualEnv.overrideSkyType.value = true; hdriSky.overrideHDRI.value = true; hdriSky.overrideExposure.value = true; hdriSky.overrideMultiplier.value = true; } }

In this script example, replace hdriTexture with your own HDR cubemap asset. This script assumes you attach it to an object with a Volume component or it'll add one if it doesn't exist.

Please note that the exact implementation may depend on the version of HDRP you're using, as the features and UI can evolve between releases.

Was this content helpful?

Start building today

Dragonfly is fully compatible with the Redis ecosystem and requires no code changes to implement.