Question: How do you change the skybox in Unity HDRP?
Answer
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:
-
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 aGlobal Volume
for scene-wide effects, or aLocal Volume
for more localized changes. -
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 selectingSky > Visual Environment
. -
Set the Sky Type: In the
Visual Environment
override, set theType
toHDRI Sky
. -
Add the HDRI Sky Override: Click on "Add Override" again, and this time select
Sky > HDRI Sky
. -
Assign Your HDR Skybox Material: Within the added
HDRI Sky
section, drag and drop your HDR skybox material into theHDRI Sky
field. You can create an HDRI skybox material by right-clicking in the Project window, navigating toCreate > Material
, then changing the Shader of the new material toHDRP/Sky/HDRISky
. -
Adjust Intensity and Exposure (if necessary): Within the
HDRI Sky
section, you can also adjust properties likeRotation
,Exposure
, andMultiplier
to fine-tune the appearance of your sky. -
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?
Other Common Game Engines Questions (and Answers)
- Can You Use C# in Unreal Engine?
- Is Unreal Engine Open Source?
- Can Unreal Engine make 2D games?
- Does Unreal Engine Use Python?
- What Language Does Unreal Engine Use?
- Does Unreal Engine Use JavaScript?
- Does Unreal Engine work on Linux?
- How Do I Uninstall Unreal Engine 5?
- Is Blender or Unreal Engine Better?
- Does Unreal Engine Work on Mac?
- Why Is Unreal Engine So Laggy?
- Can I Run Unreal Engine 5 Without a Graphics Card?
Free System Design on AWS E-Book
Download this early release of O'Reilly's latest cloud infrastructure e-book: System Design on AWS.
Switch & save up to 80%
Dragonfly is fully compatible with the Redis ecosystem and requires no code changes to implement. Instantly experience up to a 25X boost in performance and 80% reduction in cost