Change post process properties in editor mode
Asked Answered
R

10

0

Hi! I´ve been developing a tool that automaticaly changes the depth of field from a cinemachine virtual camera volume. When I update the values they change in editor, and modify the view as they are supposed, but when I try to modify again the values through editor, the view no longer changes until I save and reload the scene. Here is the code:

var cmBrain = Camera.main.GetComponent<CinemachineBrain>();
if (cmBrain == null) return;

var cmLive = cmBrain.ActiveVirtualCamera;
if (cmLive == null) return;

var volume = cmLive.VirtualCameraGameObject.GetComponent<CinemachineVolumeSettings>();
  
VolumeProfile volumeProfile = volume.m_Profile;

DepthOfField tmp;
if (volumeProfile.TryGet<DepthOfField>(out tmp))
{
    dofComponent = tmp;
}
Undo.RecordObject(dofComponent, volume.name);
dofComponent.nearFocusEnd = new MinFloatParameter(minmax.x, 0f, true);
dofComponent.farFocusStart = new MinFloatParameter(minmax.y, 0f, true);

volume.m_Profile = volumeProfile;

Thanks for the help! ^^

Rinderpest answered 24/11, 2023 at 14:6 Comment(0)
R
0

I´ve solved the problem creating a depth of field component with the values I wanted, copying it as a Json into the clipboard and then pasting it on my component.

Captura de pantalla 2023-11-30 122030

Captura de pantalla 2023-11-30 122059

Rinderpest answered 30/11, 2023 at 11:22 Comment(0)
B
0

You need to call volume.InvalidateCachedProfile(), where volume is the CinemachineVolumeSettings component. This is because CinemachineVolumeSettings is not designed to work by default with dynamically-changing volumes.

Blindfold answered 24/11, 2023 at 22:23 Comment(0)
R
0

Hi Gregoryl! I´ve tryed different places to call the function, but it still doesnt work, could you be more specific? Thank you ^^

Rinderpest answered 28/11, 2023 at 0:6 Comment(0)
B
0

Call it when you change anything in the profile

Blindfold answered 28/11, 2023 at 0:7 Comment(0)
R
0

I´ve called it before and after changing anything and still doesn´t work

var cmBrain = Camera.main.GetComponent<CinemachineBrain>();
if (cmBrain == null) return;

var cmLive = cmBrain.ActiveVirtualCamera;
if (cmLive == null) return;

var volume = cmLive.VirtualCameraGameObject.GetComponent<CinemachineVolumeSettings>();
  
VolumeProfile volumeProfile = volume.m_Profile;

DepthOfField tmp;
if (volumeProfile.TryGet<DepthOfField>(out tmp))
{
    dofComponent = tmp;
}
volume.InvalidateCachedProfile();
dofComponent.nearFocusEnd = new MinFloatParameter(minmax.x, 0f, true);
volume.InvalidateCachedProfile();
dofComponent.farFocusStart = new MinFloatParameter(minmax.y, 0f, true);
volume.InvalidateCachedProfile();



volume.InvalidateCachedProfile();
volume.m_Profile = volumeProfile;
volume.InvalidateCachedProfile();
Rinderpest answered 28/11, 2023 at 10:46 Comment(0)
B
0

You only nee to call it once, and the exact place doesn’t matter. Perhaps I’m misunderstanding what you’re trying to do. Can you show me an image of the Volume Settings component inspector in your vcam?

Blindfold answered 28/11, 2023 at 12:45 Comment(0)
B
0

Normally CinemachineVolumeSettings can do dynamic focus tracking. Do you have it set up like this?

image

Blindfold answered 28/11, 2023 at 12:54 Comment(0)
R
0

I was trying to change the end of the near range and the start of the far range on a manual depth of field. I´ve tryed calling it once in different lines of the code so then I called it multiple times :sweat_smile:. Here is the inspector:

Rinderpest answered 28/11, 2023 at 13:33 Comment(0)
B
0

ok, I understand now. The cached volume only applies when focus tracking is enabled. In your case it’s a little trickier. You have to delete the hidden dynamic volume that CM constructs under the hood.

When you change a setting in the profile, delete the hidden child of the main camera named “__CMVolumes”. Let me know if that works.

Blindfold answered 28/11, 2023 at 15:4 Comment(0)
R
0

I´ve tryed destroying the child called “_CMVolumes”. I succesfuly destroy it but still doesn´t work. After calling my script ,values in editor doesnt change the view

Rinderpest answered 28/11, 2023 at 18:46 Comment(0)
R
0

I´ve solved the problem creating a depth of field component with the values I wanted, copying it as a Json into the clipboard and then pasting it on my component.

Captura de pantalla 2023-11-30 122030

Captura de pantalla 2023-11-30 122059

Rinderpest answered 30/11, 2023 at 11:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.