Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Cinemachine virtual camera priorities changed from script

Discussion in 'Cinemachine' started by caosdoar, Jun 12, 2017.

  1. caosdoar

    caosdoar

    Joined:
    Oct 29, 2016
    Posts:
    26
    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.
     
  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,623
    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!
     
  3. caosdoar

    caosdoar

    Joined:
    Oct 29, 2016
    Posts:
    26
    Hi Gregory,

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

    keithkld

    Joined:
    May 14, 2015
    Posts:
    4
    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
     
  5. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,623
    @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. https://forum.unity.com/threads/pro...-a-button-in-cinemachine.501325/#post-3263086
     
    CodeRonnie likes this.
  6. keithkld

    keithkld

    Joined:
    May 14, 2015
    Posts:
    4
    Thanks for the quick reply. What i was missing is that Cinemachine also blends to a newly enabled vcam (if priority allows for it).