Cloning Volume Profiles during Runtime?

Is it possible to clone volume profiles while a game is running? I see I’m fully able to clone profiles in the editor to separate them, however, I need that to be done during gameplay.

I’m working on a splitscreen game and I’m trying to programatically alter bloom during gameplay. This is a snippet of the code I have so far:

cameraBloom.intensity.SetValue(new MinFloatParameter(4, 0, false));
cameraBloom.threshold.SetValue(new MinFloatParameter(0, 0, false));

But when it fires, it changes the threshold/intensity for the profile that all the Volume Profile’s on the Cameras share. If I split it into 4 different Volume Profiles it would work without a problem, but I can only do that manually through the editor.

Any solutions?

If anyone comes along in the future and needs to figure this out here’s what I did… Not exactly what the OP is asking, but hopefully from this folks can go further.

I wanted to change the vignette intensity at runtime. But doing so changes the values on the volume profile (scriptable object). Rather than try to carefully reset the values when leaving playmode (editor), I decided to clone the volume profile.

The trick is that the “overrides” or effects in the volume profile appear to be subassets and those need to be cloned too.

So we need to clone the volume profile and all the effects we want to change and then assign those cloned value accordingly.

   using UnityEngine.Rendering.Universal;
   using UnityEngine.Rendering;

    [SerializeField] private Volume volume;
    [SerializeField] private VolumeProfile profile;
    private VolumeProfile clonedProfile;
    private Vignette vignette;
    private Vignette clonedVignette;

    private void Awake()
    {
        //clone the profile and any components you want to change
        //I only need to change the vignette so I only clone that
        clonedProfile = Instantiate(profile);
        clonedProfile.TryGet(out vignette);
        clonedVignette = Instantiate(vignette);

        //assign the component to the cloned profile
        //seems like there should be a better way, but this works
        //you might need to experiment with the index value for other effects
        clonedProfile.components[0] = clonedVignette;
        //assign the profile to the volume
        volume.profile = clonedProfile;

    }

With this done I can change the vignette all I want at runtime and when I leave playmode (editor) the volume profile returns to the original instance and my runtime changes are lost.

I had the same problem…
I am sharing my solution for future reference. For many, this should be a generic solution.

// Instantiate volume profile
var volumeProfile = Instantiate(m_VolumeProfile);
for (int i = 0; i < m_VolumeProfile.components.Count; i++)
{
	var component = Instantiate(m_VolumeProfile.components[i]);
	volumeProfile.components[i] = component;
}

Thank you both for the solutions! Wouldn’t have guessed that the overrides needed to be cloned as well. Not working on this project anymore but I’m glad to see community engagement on this- I love seeing contribution for things like this :slight_smile:

1 Like