Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Resolved Controlling Volumetric Clouds at Runtime

Discussion in 'Scripting' started by Skyler_Hawkins, Dec 10, 2021.

  1. Skyler_Hawkins

    Skyler_Hawkins

    Joined:
    Aug 18, 2016
    Posts:
    32
    Hello,

    I'm trying to set the Volumetric Clouds Preset to "Cloudy" with a script at runtime, but I am unable to figure out how to actually do that.

    I've read through the Documentation here and the Volume Scripting API Documentation here. I just haven't really done much with controlling Volumes before and I'm hitting a wall with coming up with stuff.

    For testing, I've set up a button that when pressed calls the "CloudySky" function. However I can't get anything to work, so the only thing I have setting in it is "Debug.log"

    I feel like it's has something to do with VolumetricClouds.CloudPresets.Cloudy or VolumetricClouds.CloudPresetsParameter, but I haven't had any luck with figuring it out yet. I feel like I got close to getting it to work.

    The code below is more of just a empty shell I'm trying to figure it all out in.
    Code (CSharp):
    1. using UnityEngine.Rendering;
    2. using UnityEngine.Rendering.HighDefinition;
    3.  
    4. public class CloudControl : MonoBehaviour
    5. {
    6.    
    7.     public Volume cloud_Volume;
    8.  
    9.     public void CloudySky()
    10.     {
    11.         Debug.Log("Testing Clouds");
    12.         //Set VolumetricClouds.CloudPresets.Cloudy
    13.     }
    14. }
    15.  
    Screen Shot 2021-12-10 at 1.59.43 PM.png
     
  2. Skyler_Hawkins

    Skyler_Hawkins

    Joined:
    Aug 18, 2016
    Posts:
    32
    I was able to figure out how to get it running with help from the Volumetric Cloud Forum Thread here

    Here is a simple script that lets you change the Cloud Presets.

    Created buttons for each Preset and the buttons just call the functions below.

    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.Rendering;
    3. using UnityEngine.Rendering.HighDefinition;
    4.  
    5. public class CloudControl : MonoBehaviour
    6. {
    7.     [SerializeField] VolumeProfile volumeProfile;
    8.     VolumetricClouds vClouds;
    9.  
    10.     public void Sparse()
    11.     {
    12.         if (volumeProfile.TryGet<VolumetricClouds>(out vClouds))
    13.         {
    14.             vClouds.cloudPreset.value = VolumetricClouds.CloudPresets.Sparse;
    15.             Debug.Log(vClouds.cloudPreset);
    16.         }
    17.    
    18.     }
    19.     public void Cloudy()
    20.     {
    21.         if (volumeProfile.TryGet<VolumetricClouds>(out vClouds))
    22.         {
    23.             vClouds.cloudPreset.value = VolumetricClouds.CloudPresets.Cloudy;
    24.             Debug.Log(vClouds.cloudPreset);
    25.         }
    26.  
    27.     }
    28.     public void Overcast()
    29.     {
    30.         if (volumeProfile.TryGet<VolumetricClouds>(out vClouds))
    31.         {
    32.             vClouds.cloudPreset.value = VolumetricClouds.CloudPresets.Overcast;
    33.             Debug.Log(vClouds.cloudPreset);
    34.         }
    35.  
    36.     }
    37.     public void Stormy()
    38.     {
    39.         if (volumeProfile.TryGet<VolumetricClouds>(out vClouds))
    40.         {
    41.             vClouds.cloudPreset.value = VolumetricClouds.CloudPresets.Stormy;
    42.             Debug.Log(vClouds.cloudPreset);
    43.         }
    44.  
    45.     }
    46.  
    47. }
     
    anepicperson likes this.