Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question HDRI Sky cannot be disabled ?

Discussion in 'General Discussion' started by momo5ms1, Jun 1, 2023.

  1. momo5ms1

    momo5ms1

    Joined:
    Feb 10, 2021
    Posts:
    20
    Hello everyone,

    This might be a dumb question, I'm using HDRI Sky for the first time and I created an empty GameObject and attached a Volume and HDRI Sky to it as in the photo below, at some point in execution time, I want to change the HDRI sky and all I need to know is how to disable the HDRI Sky component.
     

    Attached Files:

  2. RockJack12

    RockJack12

    Joined:
    Jun 1, 2023
    Posts:
    2
    To disable the HDRI Sky component attached to a GameObject during runtime, you can use the following code:

    using UnityEngine;
    using UnityEngine.Rendering.HighDefinition;

    public class DisableHDRI : MonoBehaviour
    {
    // Reference to the HDRI Sky component
    private HDRISky hdriSky;

    private void Start()
    {
    // Get the HDRI Sky component attached to the GameObject
    hdriSky = GetComponent<HDRISky>();
    }

    // Method to disable the HDRI Sky component
    public void DisableHDRIComponent()
    {
    if (hdriSky != null)
    {
    // Disable the HDRI Sky component
    hdriSky.enabled = false;
    }
    }
    }

    Here's how you can use the code:

    1. Attach the DisableHDRI script to the GameObject with the HDRI Sky component.
    2. During runtime, whenever you want to disable the HDRI Sky component, you can call the DisableHDRIComponent() method on the script attached to the GameObject.
    By setting the enabled property of the HDRI Sky component to false, you effectively disable it and prevent it from affecting the scene's lighting. It may helpful for you.
     
    Last edited: Oct 22, 2023
  3. momo5ms1

    momo5ms1

    Joined:
    Feb 10, 2021
    Posts:
    20
    Try to compile this script before. I wrote the same thing but trying to GetComponent of type HDRISKY is not possible.