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.
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?
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:
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.
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.
Since you give no details about your setup or what you’re trying to do, it is difficult to help you. If you would like to post a simple test project that shows the problem, I can take a look at it.
Yeah i did no setup. Just added the component of Cinemachine Brain and boom you will see the Gizmos gone. No Cinemachine Camera or others. I’ve tried Pixel Perfect which i thought it would fix but no.
Using Unity 6000.0.3f1 URP and CM 3.1.0, nothing strange happens when I create a CMBrain.
When I create a CinemachineCamera, the expected behaviour is that the new camera will be positioned to match the Scene View camera. It has to go somewhere - that’s where it goes.
If it’s the first CM Camera in your scene, a CMBrain will be added to the main camera, and it will immediately start controlling the main camera’s transform (that’s its job) - which means that the main camera will be repositioned to match the new CM Camera.