Hello can anyone help me increment the intensity setting on the post processing vignette via script?
I looked at the API and im having a hard time wrapping my head around it
For further context, im making a script that increases the vignette intensity setting by 1 as Time.delta time increases
Are you using either the post-processing in HDRP, or Post Processing Stack V2?
If so, then you should be able to get a handle on the Vignette object. Make sure youāve check the box to allow overrides to the intensity. Then, in code, you can just do something like this:
That will set the intensity to whatever āsomeFloatValueā equals. If you want to do this over time, you can either set this in an Update statement, or in a coroutine.
Your script should have a public property for either the VolumeProfile, or the Volume that the profile is on. Then you can call profile.GetComponent<Vignette>() to get the Vignette component.
Hereās a simplified example from my code. This is using HDRPās post processing, but I think itās nearly identical to V2.
You probably have a typo or something. Show your code, both the code that calls GetComponent, and the code that declares the variable youāre calling it on.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Rendering.PostProcessing;
public class PostProcessing : MonoBehaviour
{
public PostProcessVolume RenderVolume;
private Vignette _postProcessingVignette;
void Start()
{
_postProcessingVignette = RenderVolume.profile.GetComponent<Vignette>();
}
// Update is called once per frame
void Update()
{
_postProcessingVignette.intensity.Override(1);
}
}
Ah, sorry about that. My fault. I completely forgot I created an extension method (a code shortcut) so I could call GetComponent on a volume. Instead, of GetComponent, youāll need something like this:
(Note: This is for HDRP. For PPv2, change ācomponentsā to āsettingsā.) _postProcessingVignette = RenderVolume.profile.components.FirstOrDefault(c => c is Vignette) as Vignette;
Be sure to add using System.Linq; to use this.
And hereās that extension method, though, in case you want to use it, since the above code is kind of awkward:
public static class VolumeProfileUtil
{
public static T GetComponent<T>(this VolumeProfile profile) where T : VolumeComponent
{
// Note: This is for HDRP. For PPv2, change "components" to "settings".
return profile.components.FirstOrDefault(s => s is T) as T;
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Rendering.PostProcessing;
using System.Linq;
public class PostProcessing : MonoBehaviour
{
public PostProcessVolume RenderVolume;
private Vignette _postProcessingVignette;
void Start()
{
_postProcessingVignette = RenderVolume.profile.components.FirstOrDefault(c => c is Vignette) as Vignette;
}
// Update is called once per frame
void Update()
{
_postProcessingVignette.intensity.Override(1);
}
}
components still seems to be highlighted and saying there is no assembly reference
Looks like in HDRP, itās called ācomponentsā, while in PPv2 itās called āsettingsā. Just change ā.componentsā to ā.settingsā and I think it should work.