Volume profile effects not updating?

I’m trying to create a dynamic weather system that changes the weather by modifying values on the Volume’s overrides (such as volumetric clouds, fog, etc…). However changing the values while in playmode does not change anything even though the values in the inspector are correct.

The image below shows the Fog Attenuation Distance (on the fog override) modified in playmode, which is set to 50 meters, but I’m still able to see very far away as you can see.

Interestingly, even when I delete the volume (in- or outside of playmode), there’s nothing hapenning. Only when I play around in the inspector, the values change…

Help would be very appreciated!

  • Thanks :slight_smile:

Finally found it, reading the docs earlier would be helpfull…
You have to use Override() instaed of assigning new parameters. However the values shouldn’t be applied in the inspector when the effect itself is not taking place.

1 Like

If possible can you share the part of the document, please? I’m trying to setup a dynamic Depth of Field and I’m very close but the Update() method doesn’t work. The Override() you’re mentioning could be the solution and I’m trying to find that part but if you can share that part of the document that would be great!

I think it was here. You can use the .Override() on some some parameters, e.g. on the DepthOfField component of a volume, you’d use yourDepthOfField.focusDistanceMode.Override(16) .

Hope this helps :), this is very bad ux in my opinion, there is no way you’d know to use that function instead of just assigning a value…

Hey, thanks for your quick reply! Indeed this is unnecessarily complicated and very few resources for this. I think it is getting clearer, but I encountered something interesting while following the documentation you sent.

This is from the documentation:

fog.enabled.overrideState = overrideFog;
fog.enabled.value = enableFog;

and this is my implementation:

 depthOfField.enabled.overrideState = overrideDepthOfField;
depthOfField.enabled.value = enableDepthOfField;

I’m receiving errors for both statements:

‘DepthOfField’ does not contain a definition for ‘enabled’ and no accessible extension method ‘enabled’ accepting a first argument of type ‘DepthOfField’ could be found (are you missing a using directive or an assembly reference?)

While checking the documentation I noticed that it says High Definition RP
9627959--1367642--upload_2024-2-6_23-17-23.png

I’m using URP, are these different things? Is there a different way to do it for URP? I have discovered that I don’t have the High Definition RP package installed so I am installing it right now. However, if you know please enlighten me if URP and HDRP are different things therefore if the documentation changes. Thank you!

Yes, URP and HDRP are btw completely different things. They’re both render pipelines, and URP is a graphics pipeline aiming to support all platforms (such as mobile but also pc), where HDRP is mainly for high-end graphics, something you’d see done with unreal for example. As far as I know, you can’t use both at the same time right now. You should go and look through the docs/or watch some tuts to get more into the differences of both.

Looking at your problem, both the volume framework for both pipelines should be pretty similar, hope thta helps!

Thank you so much for your help! Yes, it did help me solve the issue! It was a struggle but I managed to pull it off. In case if anyone else comes here I’m sharing the script for Dynamic Depth Of Field for URP. It’s not perfect but it works!

using System.Collections;
using System.Collections.Generic;
using Unity.VisualScripting;
using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.Rendering.Universal;

public class PostProcessing : MonoBehaviour
{

    public VolumeProfile volumeProfile;

    DepthOfField depthOfField;

    [Header("Focus Distance Settings")]
    public float maxFocusDistance;
    public float minFocusDistance;
    public float speedFocusChange;
    public float changeDepthOfField;

    [Header("Raycast Variables")]
    public float distanceBetween; //Global variable to store the Vector3.Distance variable to calculate distance between camera and raycast hit.distance

    public LayerMask layerMask;

    static float t = 0.0f; //starting value for the Lerp



    void Start()
    {

        if(volumeProfile.TryGet<DepthOfField>(out depthOfField))
        {
            Debug.Log("Depth of Field Component Initiated");
            depthOfField.active = true;
            depthOfField.mode.overrideState = true;
            depthOfField.focalLength.overrideState = true;
            depthOfField.focusDistance.overrideState = true;
        }
    }

    void Update()
    {
        RaycastHit hit;

        if(Physics.Raycast(Camera.main.transform.position, Camera.main.transform.TransformDirection(Vector3.forward), out hit, Mathf.Infinity, layerMask))
        {
            Debug.DrawRay(Camera.main.transform.position, Camera.main.transform.TransformDirection(Vector3.forward) * hit.distance, Color.yellow);
            Debug.Log("Raycast hit: " + hit.transform.name);

            //Calculate the distance between camera and the raycast hit
            distanceBetween = Vector3.Distance(Camera.main.transform.position, hit.point);

            depthOfField.focusDistance.value = distanceBetween;

        }
    }

}
1 Like