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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Question Editing visual environment sky type in game in HDRP 12.1.7

Discussion in 'Scripting' started by greeenlaser, Oct 30, 2022.

  1. greeenlaser

    greeenlaser

    Joined:
    Oct 5, 2018
    Posts:
    6
    Hey, is it possible to edit the visual environment sky type in game?
    I can edit the sky type manually in game but editing it through code seems to have no effect no matter which value i set it to
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.Rendering;
    5. using UnityEngine.Rendering.HighDefinition;
    6.  
    7. public class Test_VisualEnvironment : MonoBehaviour
    8. {
    9.   [SerializeField] private VolumeProfile Profile;
    10.   private VisualEnvironment visualEnvironment;
    11.  
    12.   private void Start()
    13.   {
    14.     if (Profile.TryGet<VisualEnvironment>(out VisualEnvironment ve))
    15.     {
    16.       visualEnvironment = ve;
    17.     }
    18.     visualEnvironment.skyType = new(2, true);
    19.   }
    20. }
     
  2. VRbOB

    VRbOB

    Joined:
    Mar 28, 2017
    Posts:
    2
    Hey greenlaser, I am having the exact same problem with VisualEnvironment, and it's driving me nuts. I'm even using sharedProfile, which I understand to be the correct way to ensure you're affecting the Volume that you see in the Inspector:

    Code (CSharp):
    1.     private Volume skyVolume;
    2.     private VolumeProfile profile;
    3.     private VolumetricClouds volumetricClouds;
    4.     private VisualEnvironment visualEnvironment;
    5.  
    6.     void Start()
    7.     {
    8.         profile = skyVolume.sharedProfile;
    9.         profile.TryGet(out volumetricClouds);
    10.         profile.TryGet(out visualEnvironment);
    11.     }
    Here's the bizarre part: Everything works as expected for the 'volumetricClouds' defined above, but NOT for the 'visualEnvironment', even though both are referring to the same shared profile Volume 'skyVolume'.

    If I change parameter values in the VolumetricClouds Override of this Volume, they not only affect the volume clouds in the scene perfectly, but I can see the values change in the Inspector.

    But if I change parameter values in the VisualEnvironment Override from the same Volume, they do nothing. If I query the profile, the parameters report that they have indeed changed; but neither the Game View, Scene View or Inspector reflect those changes.

    Did you find a resolution? Does anybody else have a resolution?

    I am using Unity 2022.2.18 and HDRP 14.0.7.[/QUOTE]
     
  3. VRbOB

    VRbOB

    Joined:
    Mar 28, 2017
    Posts:
    2
    I found the solution that worked for me:

    A) I had to set the profile AGAIN before the additional TryGet:

    Code (CSharp):
    1.     void Start()
    2.     {
    3.         profile = skyVolume.sharedProfile;
    4.         profile.TryGet(out volumetricClouds);
    5.         profile = skyVolume.sharedProfile;
    6.         profile.TryGet(out visualEnvironment);
    7.     }
    8.  
    B) When I tested the parameters for 'visualEnvironment' I was querying the skyVolume.profile.components[int].parameters[int]' so got faked out. As near as I can tell, because I didn't repeat the 'profile = skyVolume.sharedProfile;' assignment before the 2nd TryGet above, my 'profile.TryGet(out visualEnvironment);' actually created a clone of the profile; so I was changing parameters in the clone, and reading them back from the clone. Total fake out.

    As soon as I inserted the 2nd 'profile = skyVolume.sharedProfile;' before the 'profile.TryGet(out visualEnvironment);' AND changed my verification query to 'skyVolume.sharedProfile.components[int].parameters[int]' then everything worked as expected and reported back as expected. And the values in the Inspector reflected that.
     
    Last edited: Jun 21, 2023