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 a
Global Volume for scene-wide effects, or a
Local 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 selecting
Sky > Visual Environment.
Set the Sky Type: In the
Visual Environment override, set the
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 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
Adjust Intensity and Exposure (if necessary): Within the
HDRI Sky section, you can also adjust properties like
Multiplier 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:
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.