Search Unity

Priority not working?

Discussion in 'Cinemachine' started by Kev00, May 23, 2018.

  1. Kev00

    Kev00

    Joined:
    Dec 6, 2016
    Posts:
    229
    I'm having a strange issue with the vcam set to the highest priority not becoming live.

    In this case, one vcam is set to 0 (VCamMainFloater) and another vcam (TargetingVCam) set to 1, but VCamMainFloater remains live.

    The only difference between the two cameras is that VCamMainFloater is a free look camera and the other is a normal virtual camera.


    upload_2018-5-23_14-23-51.png

    I've upgraded to 2018.2 and I'm using Cinemachine 2.1.13.

    I created a simple script to make sure there are no other vcams in my scene. In fact, I'm using this iterator to flip all vcams back to priority 0;

    Code (CSharp):
    1.  public void DebugVCams()
    2.         {
    3.             int n = CinemachineCore.Instance.VirtualCameraCount;
    4.             for (int i = 0; i < n; i++)
    5.             {
    6.                 CinemachineVirtualCameraBase vcam = (CinemachineVirtualCameraBase)CinemachineCore.Instance.GetVirtualCamera(i);
    7.                 Debug.Log(vcam.gameObject.name + ", Priority= "  + vcam.Priority.ToString());
    8.             }
    9.         }
    Here are the results. I don't understand why VCamMainFloater is live.
    upload_2018-5-23_15-6-42.png
     
    Last edited: May 23, 2018
  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,719
    The brain will only notice vcams that are on layers that its camera component can see. Is the TargetingVCam on an invisible layer?
     
    macka1080 likes this.
  3. Kev00

    Kev00

    Joined:
    Dec 6, 2016
    Posts:
    229
    yes, that's the problem. :) thank you.
     
  4. zIyaGtVm

    zIyaGtVm

    Joined:
    Dec 27, 2017
    Posts:
    131
    I have the same problem and all the vCam are on the default layer which is visible. Is there any other reason why priority not working on highest vcam?
     
  5. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,719
    Are you using timeline with CM track?
     
  6. zIyaGtVm

    zIyaGtVm

    Joined:
    Dec 27, 2017
    Posts:
    131
    No.I'm not using timeline CM track. Another thing is that the wrong vcam is always the lowest vcam in Hierarchy.
     
  7. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,719
    What version of CM are you using?
    Can you show images please of hierarchy, and sample vcam inspector?
    Do you have debug text on in brain?
    Do you have more than one Brain in your scene?

    upload_2019-3-7_10-23-45.png
     
  8. zIyaGtVm

    zIyaGtVm

    Joined:
    Dec 27, 2017
    Posts:
    131
    What version of CM are you using? I'm using ver2.2.8
    Do you have debug text on in brain? Yes.
    Do you have more than one Brain in your scene? No I have only one CM Brain.
    eg1.png
     
  9. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,719
    What are Near Camera and Far Camera?
    What vcam to you want to be Live? (show inspector while game running)
    What vcam is being Live in its place? (show inspector while game is running)
     
  10. zIyaGtVm

    zIyaGtVm

    Joined:
    Dec 27, 2017
    Posts:
    131
    What are Near Camera and Far Camera? They are non-CM camera watching other layers.
    1.png 2.png
    What vcam to you want to be Live? CM vcam F
    3.png
    What vcam is being Live in its place? SideRoom Hallway VCam
    4.png
     
  11. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,719
    Well that's just weird. I can't explain it from the pictures alone.
    What happens when you manually change the priorities of the vcams while the came is running? Can you get vcam F to be live?
    Can you create another vcam while the game is running and get it to be live?
    What happens if you press Solo?
    Are you 100% sure that you have no timelines in your scene?
     
  12. zIyaGtVm

    zIyaGtVm

    Joined:
    Dec 27, 2017
    Posts:
    131
    In fact I change the vcam F's priority to 11 , the Brain still turns to VCam who's priority is 9 just like Vcam F is inactive but it is certainly enable.
    Then I create another new vcam while the game is running ,the new vcam becomes live with priority 10.
    If I press solo VCam F becomes live.

    I use timeline but I'm sure I never use cinemachine tracks.:confused:
     
    Last edited: Mar 7, 2019
  13. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,719
    I'm thinking you have a script somewhere that's forcing vcam F's priority to something lower, and that the inspector's display is just not refreshing. Could something like that be happening?
     
  14. zIyaGtVm

    zIyaGtVm

    Joined:
    Dec 27, 2017
    Posts:
    131
    I also thought it before, after the Priority 9 Vcam is live I made an editor button to print every vcam's prioriry, and the result showed vcam F's priority is 11.So I'm really confused.
     
  15. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,719
    Can you try just deleting vcam F and making a new one?
     
  16. zIyaGtVm

    zIyaGtVm

    Joined:
    Dec 27, 2017
    Posts:
    131
    Code (CSharp):
    1.  
    2. public void RecoverEnvironmentLevel(Transform pivot, Transform environment)
    3. {
    4.       if (pivot != null && environment != null)
    5.       {
    6.             environment.SetParent(pivot.root);
    7.             pivot.parent.SetParent(transform);
    8.             pivot.localEulerAngles = Vector3.zero;
    9.        }
    10. }
    I found this weird result may have something to do with this method.
    Maybe vcam's hierarchy level change will make it ignore current highest priority?
     
  17. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,719
    aaahhh!
    If vcam F is parented to another vcam, it won't be seen by the brain. I bet that's what's happening.
     
    Taylor_G likes this.
  18. daraOke

    daraOke

    Joined:
    May 8, 2015
    Posts:
    9
    Ahem... Any one still having similar issues now? Cos I am...
     
  19. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,719
    Can you elaborate? What are you doing and how is it misbehaving? We know of no current outstanding issues in the vcam priority system.
     
  20. VincentAbert

    VincentAbert

    Joined:
    May 2, 2020
    Posts:
    123
    Hello,

    I do have a similar issue that is driving me crazy... I'm using Cinemachine 2.7.1 in Unity 2019.4.18 LTS, and it seems my cinemachine brain doesn't always go to the higher priority Cam. It's been happening for a few days I think (maybe after a Unity update), and for example, it regularly stays stuck on my aim cam despite its priority beeing lower than the main one. I "fixed" it by having the priority difference higher (used to be 10 vs 11, changed it to 8 vs 12) and it works somehow better but it's still quite buggy and quite often goes to (or starts the scene with) the wrong cam, despite the priorities being set as intended...
    I checked everything you mentionned here, it doesn't seem to apply...
     
  21. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,719
    If there are multiple active vcams with the same (highest) priority, then which one is chosen will depend on activation order, and is not deterministic.

    Also, to be chosen, vcams must be on a layer visible to the Camera's culling mask.

    And finally, active timelines with Cinemachine tracks can override the priority system.
     
  22. urilache

    urilache

    Joined:
    Nov 23, 2013
    Posts:
    7
    Just had this issue with a lower priority camera being active instead of a higher priority one.

    More info:
    In our game we switch between different Cameras depending on the characters abilities. Previously we were hiding them, but the input was not sent to the hidden cameras during blending (which makes sense), so we opted for a priority system: 0 if deactivated, the actual value if active and let cinemachine brain take care of the active camera.
    This created the issue that sometimes cinemachine brain remains stuck in a priority 0, instead of the default camera which has priority 1. This tends to happen when the user dies and we disable any active abilitites and their cameras, while putting for a few frames a WarpBehindPlayer camera (for positioning after respawning).
    I'm using Unity 2020.3.15f2 and Cinemachine v2.6.5.​

    How I reproduced it faster:
    After investigating ways to reproduce it, I came up with a brute-force to reproduce it easily (25%) in my project using 3 camera DefaultCam, CamForBlend, CamSpammer.
    I subscribe to the m_CameraActivatedEvent and when CamForBlend is activated I activate on one frame and deactivate on the other the CamSpammer. If sometime during the next x frames I deactivate the CamForBlend at the end of the sequence, the CamSpammer will remain active, even though it has a lower priority.
    My current fix/hack is:
    If I detect that there is no active blend and the current camera has a priority of 0 for 2 frames, I lower it to -1. Unity will detect the priority change and will fix the camera. The weird part is that it goes through the CamForBlend before returning to the default one, as if they had the same priority.
     
  23. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,719
    @urilache Can you prepare a small test project that shows this problem and DM it to me?
     
  24. urilache

    urilache

    Joined:
    Nov 23, 2013
    Posts:
    7
    just sent the small test project.
    Thank you for looking into this issue.
     
    Gregoryl likes this.
  25. halley

    halley

    Joined:
    Aug 26, 2013
    Posts:
    2,442
    I know this is an old thread, but I was trying to debug this for a while, until I realized that in my case the CM Brain actually was selecting and using my dialogue camera at high priority, but my dialogue system was setting Time.timeScale to zero, so the camera blend was not taking effect. Answer: CM Brain's "Ignore Time Scale" needed to be set, to allow the camera to move to the right position.