Last active
November 2, 2020 01:02
-
-
Save simonrcodrington/e9a0d6e31b8360e5cee8dba758671fb1 to your computer and use it in GitHub Desktop.
Unity URP Disabling volume components at run time
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using UnityEngine.Rendering; | |
using UnityEngine.Rendering.Universal; | |
/// <summary> | |
/// Unity's URP profile uses 'Volumes' attached to the camera to apply it's new post processing effects. | |
/// Below is how you can access one of the components(e.g the depth of field component) and disable it at runtime | |
/// </summary> | |
class urp_dof_conditional : MonoBehaviour | |
{ | |
[Tooltip("Determines if the selected camera will have it's DOF enabled or disabled")] | |
public bool dofEnabled = true; | |
[Tooltip("The camera with a URP volume attached to it")] | |
public Camera targetCamera; | |
/// <summary> | |
/// On start, enable or disable to DOF attached to the target camera | |
/// </summary> | |
public void Start() | |
{ | |
//get the volume attached to the main camera | |
VolumeProfile volumeProfile = targetCamera.GetComponent<Volume>().profile; | |
//get the DOF component from the volume and se it | |
DepthOfField depthOfField; | |
volumeProfile.TryGet(out depthOfField); | |
if(depthOfField != null) depthOfField.active = dofEnabled; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment