Search Unity

Unexpected CM switch in runtime mode

Discussion in 'Cinemachine' started by IdeoG, Oct 1, 2018.

  1. IdeoG

    IdeoG

    Joined:
    Oct 14, 2017
    Posts:
    22
    Hello community,

    In my new project i decided to use cinemachine plugin for cameras. First look was great. Cinemachine does a lot of work, which i'm used to code before. It was simple free look camera.
    So, i tried to complicate my project and added a home with entrance, door to first level and a stairs to a second level. So, i examined clear shot example and found, clear shot camera with virtual cameras without Body component is a nice approach to make best expirience of playing. In required position i put two box colliders and gave them cm trigger script. I wrote a simple class which hold 2 function which called on trigger enter event.
    Code (CSharp):
    1. public class HouseTriggerEvent : MonoBehaviour
    2. {
    3.     [SerializeField] private CinemachineVirtualCameraBase _enterCamera;
    4.     [SerializeField] private CinemachineVirtualCameraBase _exitCamera;
    5.  
    6.     public void OnHouseEnter()
    7.     {
    8.         _enterCamera.Priority = 15;
    9.         _exitCamera.Priority = 10;
    10.  
    11.         _enterCamera.enabled = true;
    12.         _exitCamera.enabled = false;
    13.     }
    14.  
    15.     public void OnHouseExit()
    16.     {
    17.         _enterCamera.Priority = 10;
    18.         _exitCamera.Priority = 15;
    19.        
    20.         _enterCamera.enabled = false;
    21.         _exitCamera.enabled = true;
    22.        
    23.     }
    24. }
    Maybe it wasn't best solution, but it does work... As i thought..
    In some occasions, camera with disabled cinemachine virtual camera component gets live. I don't know what to do. I lost.
    Please, help me to find a clue to get it worked.
     
  2. IdeoG

    IdeoG

    Joined:
    Oct 14, 2017
    Posts:
    22
    Also, i had unexpected behaviour with virtual camera which doesn't have body component.. It moves.. I tried to fix this.. But for now i have lost.
     
  3. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,711
    A disabled vcam can be live during a blend. If you disable it, and the brain is trying to blend with it, the vcam will be artificially kept on "life-support" until the blend is finished. Is that what you're seeing? If so, and you don't want that behaviour, make a setting to always cut to that vcam, not blend.

    I don't know what you mean when you say the vcam moves. Do you mean changes its position, or changes its rotation?

    Also, in your script, it's not necessary to both change the priority and enable/disable. Do one or the other. It's not harmful, but it adds confusion.

    Consider also using the CinemachineTriggerAction script for your trigger zones. It will save you some coding :)

    upload_2018-10-1_17-39-24.png
     
    Gametyme likes this.
  4. IdeoG

    IdeoG

    Joined:
    Oct 14, 2017
    Posts:
    22
    @Gregoryl Thanks for your fast comment.

    its behaviour hasn't exactly you described. I'll give you more information about clear shot camera. upload_2018-10-2_0-50-54.png
    This is hierarchy of cameras system in edit mode. Unexpected behaviour occurs then CM fishman first entrance disabled and there aren't any blends in progress. It changes status from disabled to live then vcam component is disabled.

    vcam changes its position.

    I'm using CinemachineTriggerAction script, as it done in ClearShotExample. Actually, cameras switch seemed doesn't worked in a right maneer. So, i forced to write a script.
     
    Last edited: Oct 1, 2018
  5. IdeoG

    IdeoG

    Joined:
    Oct 14, 2017
    Posts:
    22
    I thought i will fix a "bug" with one more crutch, but i get to a point, where i started before CinemachineTriggerAction script as you mentioned.
     
  6. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,711
    Is CM Fisherman a ClearShot? If so, then it's responsible for enabling/disabling the children based on target visibility. That's what it's for. If you set up the ClearShot correctly then you do not need an enable/disable script, or a TriggerAction script. Remove those scripts, and let's look at how you set up the ClearShot. Can you show me inspectors for the ClearShot itself, and for one of the vcam children that is having problems?

    What ClearShot example did you look at?

    What version of Cinemachine are you using? And what version of Unity?
     
  7. IdeoG

    IdeoG

    Joined:
    Oct 14, 2017
    Posts:
    22
    Yes CM Fisherman is a ClearShot.
    I created triggers inside a house because i got anxious behaviour with camera switching. Probably it occured because of best shot idea of cinemachine. For example, there're small entrance in a house. Player opens door and steps into first level. CM first level camera is supposed to be live (it's position in a up corner), but entrance camera has better best shot no matter prioroty it get live.

    I'm using Unity 2018.2.5f1. Cinemachine plugin has 2.2.7 version.
     
  8. IdeoG

    IdeoG

    Joined:
    Oct 14, 2017
    Posts:
    22
  9. IdeoG

    IdeoG

    Joined:
    Oct 14, 2017
    Posts:
    22
    I took pictures in editor mode.
     
  10. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,711
    My guess is that you have the CM collider set up improperly.

    1. Your vcams are moving because you have "Avoid Obstacles" checked. That tells the vcams to move in order to resolve occlusions. For sure you don't want that.

    2. You have "Optimal target distance" set to 1. This will favour vcams whose distance from target is close to 1. Is that what you want? I don't know anything about your geometry so I can't say. Best to turn off that feature for now by setting that field to 0.

    Can you show me the inspector for your player? Is it really just called "Transform"?
     
  11. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,711
    Also: if your player is made up of multiple shapes, and the "Transform" target is buried inside it, it's possible that the Collider is fooled into thinking that the player is occluded by its own geometry, resulting in vcams falsely thinking that the target is occluded. The solution for that is to tag all the player's geometry with a tag (e.g. "player"), and tell the collider to ignore objects with that tag.
     
  12. IdeoG

    IdeoG

    Joined:
    Oct 14, 2017
    Posts:
    22
    1. It get worked. Turning off "Avoid Obstacles" solved the issue.

    2. I thought it was default value. It read documentation but didn't catch what exactly does it mean. Now it's clear.

    3. Yeah, game designer named it just a Transform. It's a little bit higher then player's head.
     
    Gregoryl likes this.
  13. IdeoG

    IdeoG

    Joined:
    Oct 14, 2017
    Posts:
    22
  14. IdeoG

    IdeoG

    Joined:
    Oct 14, 2017
    Posts:
    22
    Tagged all inner gameobject with "player", but have same glitches :/
     
  15. IdeoG

    IdeoG

    Joined:
    Oct 14, 2017
    Posts:
    22
    Is any way i can give you more inforamtion?
     
  16. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,711
    What are the glitches?
     
  17. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,711
    Did you set this?

    upload_2018-10-1_18-49-16.png
     
  18. IdeoG

    IdeoG

    Joined:
    Oct 14, 2017
    Posts:
    22
    Sorry, I mean unexpected behavior that lead a inactive camera to be live.
     
  19. IdeoG

    IdeoG

    Joined:
    Oct 14, 2017
    Posts:
    22
    Yes, I placed it to ignore player tag.
     
  20. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,711
    1. I just noticed that your child vcams have a Standby Update mode of "never". This means they will never evaluate shot quality, so ClearShot will be unable to choose. Set them to "Always" for now, until we get this working.

    2. Did you set the "Optimal Target Distance" to 0?

    3. Set all the child vcam priorities to the same thing (e.g. 10)

    4. Does the player root object also have the Player tag?