Search Unity

Bug Gizmos incorrectly positioned when Cinemachine Virtual Camera is in use

Discussion in 'Cinemachine' started by florianhanke, Feb 8, 2021.

  1. florianhanke

    florianhanke

    Joined:
    Jun 8, 2018
    Posts:
    426
    When I use a Cinemachine Virtual Camera in a 2D project, the position of the Gizmos is incorrect. When I disable it, the gizmos are positioned correctly.

    Coincidentally, Camera.main.ScreenToWorldPoint _seems_ to be wrong, but it is correct in regards to the Gizmos, but not in regard to what the Cinemachine Virtual Camera sees.

    Here's a GIF showing the Gizmo positions and the GameObject positions. For example, the top left light Gizmo (the top left light bulb Gizmo) is positioned far away from its top left light.
    CinemachineGizmos.gif
    It looks as though the Gizmo positions are fractions of the actual positions towards the zero point.

    Aiming also is relative to the Gizmo's position (using Camera.main.ScreenToWorldPoint), not the actual position.

    Is this a bug?
    Or is this a mistake / wrong assumption I am making re Cinemachine?

    Here are my settings:
    Screenshot 2021-02-08 at 13.57.42.png
    Screenshot 2021-02-08 at 13.58.04.png

    Thanks for any help in advance!
     
  2. gaborkb

    gaborkb

    Unity Technologies

    Joined:
    Nov 7, 2019
    Posts:
    856
    I don't see how Cinemachine can modify your Gizmo positions. How do you draw your gizmos? Could you show the code?

    Could you elaborate on this?
     
    florianhanke likes this.
  3. florianhanke

    florianhanke

    Joined:
    Jun 8, 2018
    Posts:
    426
    I do not have any custom Gizmos. If you look at my example GIF, you can see that the default Unity Light2D gizmo is not positioned over the light, but is positioned roughly halfway towards the 0,0 point.
    It's not how I position my Gizmos - the issue must be either a bug, or more likely I admit, my assumptions about how this is supposed to work.

    I'll try. I am using a Pixel Perfect Camera component on my main Camera, plus a Cinemachine Brain. I also have a Cinemachine Virtual Camera in the scene which I use a Framing Transposer on a Cinemachine Target Group for my 4 players. The Framing Transposer will change the ortho lens size depending on its needs.

    Depending on the Reference Resolution on the Pixel Perfect Camera (let's say 480x320), I have to set the ortho size lens to a fixed value (e.g. 11), so that the position of the Gizmos is congruent with the position of the actual game objects in the scene. Since I use a Cinemachine Target Group, that means I have to set the minimum and maximum ortho size also to 11, so it can't "zoom" in or out anymore, so the Gizmo is positioned correctly and calls to Camera.main.ScreenToWorldPoint return correct values.

    In the GIF you can see the disparate positions:
    gizmo-issue2.gif

    The Gizmos of course are just a symptom, since Camera.main.ScreenToWorldPoint also does not correspond to what is rendered.

    I am mainly wondering – am I not using the system correctly or am I making wrong assumptions that when using a Pixel Perfect Camera, I should be able to change ortho lens sizes? Or do I have to set a Camera.current to the CM virtual camera somehow?

    But basically my expectation is when using Unity 2D that the gizmos line up with the actual game objects.
     
    Last edited: Feb 10, 2021
    gaborkb likes this.
  4. gaborkb

    gaborkb

    Unity Technologies

    Joined:
    Nov 7, 2019
    Posts:
    856
    I understand the problem now. ;)

    Not to any value. Pixel Perfect Camera component determines which values are ok.
    I think you are missing CinemachinePixelPerfect extension on your vcams. This extension applies the Pixel Perfect Camera component's constraints to your vcam. You can add it from the Add Extension dropdown.
     

    Attached Files:

    florianhanke and Gregoryl like this.
  5. florianhanke

    florianhanke

    Joined:
    Jun 8, 2018
    Posts:
    426
    Thank you, that solves the issue! :)
     
    gaborkb likes this.