Cinemachine virtual camera priorities changed from script

Hi,

I am modifying the priority for cinemachine virtual cameras from a script to switch cameras based on script events. But I’m having a problem with the “SaveDuringPlay” functionality as those modifications are saved.

Should I be changing priorities from scripts to switch between cameras to begin with? If so, is there a way to avoid those changes been saved?

Cheers.

You can disable the SaveDuringPlay for any property by adding the [NoSaveDuringPlay] attribute to it. Since the priorities are meant to be changed during runtime, it makes sense to exclude the m_Priority member from SaveDuringPlay. We will make this change in the next release. In the meantime, you can just add that attribute yourself to CinemachinrVirtualCameraBase.cs, which is where m_Priority is defined.

Thanks for the feedback!

Hi Gregory,

I will do that. Thank you for the (really quick) answer.

I could use some best practices guidance with the second part of the question. What is the concept behind switching cameras based on play, not the timeline, for example using a trigger collision, or a script event to switch cameras?

I’ve been through the documentation several times and several tutorials. It doesn’t seem like switching cameras like thisa focus for CM, but is not intended to be used like this?

I can see two ways to do this:

  1. Animation triggers
  2. Clearshot camera and scripting priority

@keithkid The Priority system of controlling the current camera during gameplay is central to Cinemachine. The idea is that a game event (could be a trigger, a script, a UI control, a timer, anything you like) triggers the running of a script which enables/disables vcams, or modifies their priorities. The vcam with the highest priority (or the most recently-enabled one if multiple vcams have the highest priority) will drive the Unity Camera.

Here is a similar question. Maybe the answer will help. Programmatically turning on and off a VCam with a button in Cinemachine - Unity Engine - Unity Discussions

1 Like

Thanks for the quick reply. What i was missing is that Cinemachine also blends to a newly enabled vcam (if priority allows for it).