Search Unity

Smooth canvas resizing along with camera

Discussion in 'UGUI & TextMesh Pro' started by tropicalgames, Nov 22, 2014.

  1. tropicalgames

    tropicalgames

    Joined:
    May 15, 2014
    Posts:
    22
    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:

    Code (CSharp):
    1. if (Input.touchCount == 2) {
    2.  
    3.             newPos = transform.position;
    4.  
    5.             Touch touchZero = Input.GetTouch(0);
    6.             Touch touchOne = Input.GetTouch(1);
    7.  
    8.             Vector2 touchZeroPrevPos = touchZero.position - touchZero.deltaPosition;
    9.             Vector2 touchOnePrevPos = touchOne.position - touchOne.deltaPosition;
    10.  
    11.             float prevTouchDeltaMag = (touchZeroPrevPos - touchOnePrevPos).magnitude;
    12.             float touchDeltaMag = (touchZero.position - touchOne.position).magnitude;
    13.  
    14.             float deltaMagnitudeDiff = prevTouchDeltaMag - touchDeltaMag;
    15.  
    16.             if(deltaMagnitudeDiff != 0){
    17.                 camera.orthographicSize = Mathf.Clamp(camera.orthographicSize + deltaMagnitudeDiff * zoomSpeed, minZoom, maxZoom);
    18.                 UpdateCamera();
    19.             }
    20.         }
    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:
    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 :D) I'm just adding -0.2f to camera's ortographic size:

    Code (CSharp):
    1. if (Input.GetMouseButtonUp (0)) {
    2.             camera.orthographicSize = Mathf.Clamp(camera.orthographicSize - 0.2f, minZoom, maxZoom);
    3.             UpdateCamera();
    4.         }
    Any idea what I'm doing wrong? Help!
     
  2. SONDERFORMAT

    SONDERFORMAT

    Joined:
    Sep 19, 2014
    Posts:
    3
    I have the same problem.
     
  3. tropicalgames

    tropicalgames

    Joined:
    May 15, 2014
    Posts:
    22
    Still not fixed. I'm pretty desperate right now :)
     
  4. pixpusher2

    pixpusher2

    Joined:
    Oct 30, 2013
    Posts:
    121
    Just curious, why not use Screen space - Overlay canvas mode instead so it doesn't get affected by camera zoom?
     
  5. runevision

    runevision

    Joined:
    Nov 28, 2007
    Posts:
    1,892
    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.
     
  6. tropicalgames

    tropicalgames

    Joined:
    May 15, 2014
    Posts:
    22
    @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 :( Gonna report that issue..

    Hmm.. http://issuetracker.unity3d.com how to add a new issue :( ?
     
    Last edited: Nov 28, 2014
  7. runevision

    runevision

    Joined:
    Nov 28, 2007
    Posts:
    1,892
  8. L-Tyrosine

    L-Tyrosine

    Joined:
    Apr 27, 2011
    Posts:
    305
  9. Gizmoi

    Gizmoi

    Joined:
    Jan 9, 2013
    Posts:
    327
    Have you tried calling Canvas.ForceUpdateCanvases in your if check? This should force the canvas to snap to the current camera correctly.
     
  10. L-Tyrosine

    L-Tyrosine

    Joined:
    Apr 27, 2011
    Posts:
    305
    Yes... same results.

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

    Attached Files:

  11. Jaroslav-Stehlik

    Jaroslav-Stehlik

    Joined:
    Feb 20, 2012
    Posts:
    485
    I have still this problem in Unity 5.1.1f1
    on a perspective camera