Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Bug camera has curious constant rotation around target in editor mode - 2D project

Discussion in 'Cinemachine' started by NikkiSIF, Feb 4, 2022.

  1. NikkiSIF

    NikkiSIF

    Joined:
    May 15, 2020
    Posts:
    14
    Hello,

    i'm working on a 2D project where my character runs and jumps on planets with faux gravity. I decided to add the cinemachine package to have neat camera tracking but as soon as i implement the virtual camera and set my character as the target, the camera starts rotating around the x axis (i.e. out of the2D plane!) even when i am still in editor mode.

    I tried with the last verified cinemachine version (2.6.11) and with the last release (2.8.4) and i still have the same issue.

    Could you please help me solve this problem?


    Current Unity Editor version: 2020.3.26f1


    Thanks!
     
  2. marc_tanenbaum

    marc_tanenbaum

    Unity Technologies

    Joined:
    Oct 22, 2014
    Posts:
    637
    Hi @NikkiSF! Could you please post a screenshot of your Virtual Camera's inspector?
     
    NikkiSIF likes this.
  3. NikkiSIF

    NikkiSIF

    Joined:
    May 15, 2020
    Posts:
    14
    Hi, thank you for your answer, and sorry for the delay.

    Here is the requested screenshot:

    upload_2022-2-8_0-52-44.png

    and i also post the cinemachine brain on my main camera:
    upload_2022-2-8_0-52-59.png
     
  4. gaborkb

    gaborkb

    Unity Technologies

    Joined:
    Nov 7, 2019
    Posts:
    856
    That's strange, because you only have FramingTransposer in Body, which does not touch the camera rotation, just the position. Camera rotation is usually controlled by an Aim behavior.

    Could you send an image of your Hierarchy? I think, you have your vcam parented to your target, which may cause unexpected behavior.
     
  5. NikkiSIF

    NikkiSIF

    Joined:
    May 15, 2020
    Posts:
    14
    Here is the hierarchy: pretty simple at the moment

    upload_2022-2-8_16-3-0.png

    What is also surprizing is that when i open unity, the camera doesn't rotate in editor mode. Then if i launch the game, it spins as hell, and when i stop the game, now it spins also in editor mode.
     
    Last edited: Feb 9, 2022
  6. gaborkb

    gaborkb

    Unity Technologies

    Joined:
    Nov 7, 2019
    Posts:
    856
    Hmm.. Could you send me a project, where I can reproduce the issue. That'll make it easier to find the cause. :)
     
    NikkiSIF likes this.
  7. NikkiSIF

    NikkiSIF

    Joined:
    May 15, 2020
    Posts:
    14
    I tried to recreate the issue in a simpler project but.... it didn't bug this time... I'll try again
     
  8. NikkiSIF

    NikkiSIF

    Joined:
    May 15, 2020
    Posts:
    14
    Ok, i deleted most of the features of my project and i still have the issue. Here is the zip file
    (with only the "Assets" and "ProjectSettings" directories for zip size limitation - do you need other directories i didn't send?)

    EDIT: those files are not enough to open the project and see the problem, i sent you a google drive link.
     
    Last edited: Feb 10, 2022
    gaborkb likes this.
  9. gaborkb

    gaborkb

    Unity Technologies

    Joined:
    Nov 7, 2019
    Posts:
    856
    Thank you for the repro project.

    What I see is that there is a hidden vcam that CmBrain selects as Live Camera. It's called BottomRig, so I assume it is a remnant of a Freelook vcam.

    I could fix the rotation by making CM vcam1 the Live Camera by increasing its priority.

    The correct solution would be to remove those hidden gameobjects that corrupt your scene. Probably, the easiest solution would be to create a new scene, and copy over your Hierarchy.
     
    Last edited: Feb 10, 2022
    Gregoryl likes this.
  10. NikkiSIF

    NikkiSIF

    Joined:
    May 15, 2020
    Posts:
    14
    Thank you a lot for the diagnostic!

    I remember trying to add CinemachineFreelook before the Cinemachine2D, what appears to be the mistake...

    So I have a few questions after reading you:
    - how can I find a hidden camera that doesn't appear to be anywhere in my project nor hierarchy?
    - why can't I simply manually replace the liveCamera in the CmBrain? (I guess that it's just how it works)
     
  11. gaborkb

    gaborkb

    Unity Technologies

    Joined:
    Nov 7, 2019
    Posts:
    856
    You could use this script to print all gameobject to console, that have some kind of hide flag:
    Code (CSharp):
    1.  
    2. using UnityEngine;
    3.  
    4. [ExecuteAlways]
    5. public class FindAllGameobjectsInScene : MonoBehaviour
    6. {
    7.     public bool findThem;
    8.     void Update()
    9.     {
    10.         if (findThem)
    11.         {
    12.             findThem = false;
    13.             var gos = FindObjectsOfType(typeof(GameObject));
    14.             for (var i = gos.Length - 1; i >= 0; i--)
    15.             {
    16.                 if (gos[i].hideFlags != HideFlags.None)
    17.                     Debug.Log(gos[i].name);
    18.             }
    19.         }
    20.     }
    21. }
    22.  

    CmBrain selects Live Camera based on priority. It chooses the highest priority vcam from all the enabled vcams in the scene. The default priority value is 10.
     
    NikkiSIF likes this.
  12. NikkiSIF

    NikkiSIF

    Joined:
    May 15, 2020
    Posts:
    14
    Thank you so much for your help!

    After some iterations, i indeed saw that 10 was the threshold priority. I could just put 11 but I'll follow your advice and clean this scene up!

    Thank you again

    edit: I ran your script and saw a list of unwanted objects. But i still couldn't find them physically in the project in order to delete them, so I assumed they were childs of my main cam : i deleted it and create a new camera and TADAAAA: no more impostor object !
     
    Last edited: Feb 10, 2022
    gaborkb likes this.