How would I enable and disable an override in a volume through script. For example enable and disable depth of field effect.
Enabling only the full effect is my goal, not the specific parts.
How would I enable and disable an override in a volume through script. For example enable and disable depth of field effect.
Enabling only the full effect is my goal, not the specific parts.
I don’t think you can access it through GetComponent to disable the highlighted toggle like you would normally, because of how Volumes work with Volume Profiles.
If you really need it completely gone you could remove it from the shared (or cloned local) profile, but you’d need to put your settings back in when you re-add. It would be easier to toggle the Mode property between “Off” and “Bokeh”. This script added to the volume does it on key press as an example (tested in HDRP where property names are a little different) and the effect is completely disabled when the mode is set to None (“Off” for URP)
VolumeProfile volumeProfile;
DepthOfField dof;
// Start is called once before the first execution of Update after the MonoBehaviour is created
void Start()
{
Volume volume = GetComponent<Volume>();
volumeProfile = volume.sharedProfile;
if (!volumeProfile.TryGet<DepthOfField>(out dof))
{
dof = volumeProfile.Add<DepthOfField>();
}
dof.focusMode.overrideState = true;
}
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(KeyCode.F))
{
if (dof.focusMode.value == DepthOfFieldMode.Manual)
{
dof.focusMode.value = DepthOfFieldMode.Off;
}
else
{
dof.focusMode.value = DepthOfFieldMode.Manual;
}
}
}