Hello, Cinemachine doesn’t seem to work if I have UI Canvas on 2D scene. I create one object and animate it left to right and set it as Cinemachine target. The Canvas disappears and Cinemachine doesn’t seem to follow the target. Anyone had this issue? Thanks.
Can you post images of your CM inspectors (brain, vcam) and also an image of your project hierarchy? Just to make sure it's all set up correctly.
Attached are pictures. Top left box is animating from left to right. Also, you can replicate it on your end 1) create new scene 2) create ui image (box) 3) animate the box left to right 4) create another box so you can see that the first box is animating 5) create 2d virtual camera 6) put animated box into follow section 7) on your ui canvas choose screen space - camera As soon as VCam is introduced the scene view canvas keeps disappearing and I have to press F to get the canvas back into view.
You're creating a feedback loop - positioning the box in screen space, then telling the camera to follow the box in world space. Not a valid use-case. What behaviour are you trying to achieve?
Ok my intention was to use 2D Camera for a 2D game. Let’s say It’s a mobile game and I have to use UI Canvas to keep mobile screen resolutions in control. I checked out various 2D Cinemachine tutorials but none of them mention anything about UI Canvas. So, how should I use Cinemachine in 2D environment with UI Canvas? Thanks.
You can use a 2D canvas, but if it's in Camera Space, it makes no sense to use CM for it, as things are all positioned in camera space, not world space. Normally, you'll move things around in world space, get CM to track them, and if you need things to be on a 2D canvas, fixed on the screen, then you add them as overlays to what's happening in world space.
Thank you. Your last paragraph I have hard time understanding. So, I create UI Canvas and set it to “Screen Space - Overlay”? Which I tried and the yellow dot of the CM is going crazy trying to follow the animated box.
Don't use CM to follow things on the canvas. Keep the canvas separate from CM. If you're going to do the whole game on the canvas, don't use CM. You can put a canvas on top of things made with CM, as an overlay, if you want.
Interesting. Thank you for the information. This will be a new way of doing things for me and I have to re-wire my brain on 2D games. I wanted to create Mario like left to right running platformer for mobile devices. I tried a small test based on what you suggested and it looks like it might work. Sounds like UI Canvas is the last thing I apply to make the game mobile compatible.
2D games in Unity are created in the 3D world, but usually with an orthographic camera looking straight down the z axis. If you use a perspective camera, then you have the additional ability to place artwork at different depths, giving a parallax effect when you move the camera. The canvas is usually used just for UI elements like buttons and score, not for actual game objects. Take a look at this page for some 2D basics (slightly old, but still quite useful): https://unity3d.com/learn/tutorials/s/2d-game-creation