Smooth canvas resizing along with camera

Hi, I’ve just started using new canvas system and just on the start got an issue. I’ve created simple canvas with panel and image as it’s child. Canvas is Screen space - camera mode. Everything looks great until I’d use zoom-gesture, code is taken from official tutorial:

if (Input.touchCount == 2) {

            newPos = transform.position;

            Touch touchZero = Input.GetTouch(0);
            Touch touchOne = Input.GetTouch(1);

            Vector2 touchZeroPrevPos = touchZero.position - touchZero.deltaPosition;
            Vector2 touchOnePrevPos = touchOne.position - touchOne.deltaPosition;

            float prevTouchDeltaMag = (touchZeroPrevPos - touchOnePrevPos).magnitude;
            float touchDeltaMag = (touchZero.position - touchOne.position).magnitude;

            float deltaMagnitudeDiff = prevTouchDeltaMag - touchDeltaMag;

            if(deltaMagnitudeDiff != 0){
                camera.orthographicSize = Mathf.Clamp(camera.orthographicSize + deltaMagnitudeDiff * zoomSpeed, minZoom, maxZoom);
                UpdateCamera();
            }
        }

UpdateCamera function just keeps camera in larger background bounds.

And here comes a problem: when I’m zooming in or out panel just like it’s “jumping”, it’s not smooth scaling. In the same moment I have simple boxes created in OnGUI method and they’re scaling perfectly smooth.

Tried with and without pixel perfect.

Just check this simple gif:
1858804--119235--rec.gif

Light grey panel with fireball image is the panel, dark grey is created by OnGUI.
I’m not making any manipulation with canvas in any script.
Also for sake of this animation (I can’t use multitouch on desktop :smile:) I’m just adding -0.2f to camera’s ortographic size:

if (Input.GetMouseButtonUp (0)) {
            camera.orthographicSize = Mathf.Clamp(camera.orthographicSize - 0.2f, minZoom, maxZoom);
            UpdateCamera();
        }

Any idea what I’m doing wrong? Help!

I have the same problem.

Still not fixed. I’m pretty desperate right now :slight_smile:

Just curious, why not use Screen space - Overlay canvas mode instead so it doesn’t get affected by camera zoom?

We had known problems about Screen Space Camera mode for Canvas producing laggy results in some of the betas, but we fixed those a while ago. If you’re getting this issue in RC3 / the shipped 4.6 then it’s not a known problem and we’d appreciate a bug report with repro project and repro steps.

@pixpusher2 - it doesn’t seem to work with 2d… I can’t specify sorting layer and can’t see canvas at all.

@runevision - when I made this topic I was using rc3, now it’s 4.6.0f3. And update didn’t help :frowning: Gonna report that issue…

Hmm… http://issuetracker.unity3d.com how to add a new issue :frowning: ?

http://forum.unity3d.com/threads/reminder-how-to-get-bugs-fixed-quickly.266818/

Unity 5.0.1 with same problem, described here

In my case its a orthographic camera with changing orthographicSize

Have you tried calling Canvas.ForceUpdateCanvases in your if check? This should force the canvas to snap to the current camera correctly.

Yes… same results.

I created a small project showing this problem, in Unity 5.0.2.

2114903–138771–Project.zip (26 KB)

I have still this problem in Unity 5.1.1f1
on a perspective camera