Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

New Events System Issue when Panning Camera..

Discussion in 'UGUI & TextMesh Pro' started by Mikeysee, Sep 14, 2014.

  1. Mikeysee

    Mikeysee

    Joined:
    Oct 14, 2013
    Posts:
    155
    Hi Guys,

    Im having an issue trying to code up a camera panning solution using the new ui events system. Check out this video first:



    As you can see when I pan the camera the HUD jitters as if its position is off by one frame.

    I have setup my canvas to be screen space camera as I need some game stuff to be rendered in front of it.

    upload_2014-9-14_17-27-46.png

    If I set the canvas to be screen space overlay then the problem doesnt present itself.

    My panner object is a large 2d collider game object that has its z order set behind the game objects:

    upload_2014-9-14_17-6-25.png

    The Panner code is very simple:

    public class Panner : MonoBehaviour, IDragHandler
    {
    public Transform target;
    private float unit;

    public void Awake()
    {
    var p1 = UnityEngine.Camera.main.ScreenToWorldPoint(Vector3.zero);
    var p2 = UnityEngine.Camera.main.ScreenToWorldPoint(Vector3.right);
    unit = Vector3.Distance(p1, p2);
    }

    public void OnDrag(PointerEventData data)
    {
    target.Translate(-data.delta.x * unit, -data.delta.y * unit, 0f);
    }
    }

    Does anyone have any idea why its jittering?

    I thought it may be an update order issue so I tried moving the translate code out of the panner into an "LateUpdate" method but it still had the same problem.

    EDIT: I have created this simple project to show the problem: https://www.dropbox.com/s/yoxw0e6tbbu87ii/UIJiterProblem.zip?dl=0

    Cheers for any advice,
    Mike
     
    Last edited: Sep 15, 2014
    rakkarage likes this.
  2. JAKJ

    JAKJ

    Joined:
    Aug 17, 2014
    Posts:
    185
    Try adding Canvas.ForceUpdateCanvases after you have moved the canvas.
     
  3. Mikeysee

    Mikeysee

    Joined:
    Oct 14, 2013
    Posts:
    155
    Im not actually translating the Canvas, im translating the Camera transform.

    Despite that I tried Canvas.ForceUpdateCanvases and it didn't work plus it seems to "increase the sensitivity" i.e. when you move the mouse 1px it translates by 2, probably because the drag event is now being fired twice.
     
  4. Mikeysee

    Mikeysee

    Joined:
    Oct 14, 2013
    Posts:
    155
    No one have any ideas? Is there a way to change the order in which the events are processed? Or is this a bug?
     
  5. JAKJ

    JAKJ

    Joined:
    Aug 17, 2014
    Posts:
    185
    It's the weekend: Wait until the devs who actually wrote the code come back and see this. The rest of us are still learning the system by trial-and-error-and-partial-sourcecode.
     
  6. Mikeysee

    Mikeysee

    Joined:
    Oct 14, 2013
    Posts:
    155
    Good point :) Worst comes to the worst ill manually implement panning / zooming without using the new events system.
     
  7. rakkarage

    rakkarage

    Joined:
    Feb 3, 2014
    Posts:
    683
    How are the two items in the video related in hierarxhy? And how related to camera?
    Is one a child of other or camera?

    also does canvas have pixel perfect on? Could that be the culprit? Idk
     
  8. Mikeysee

    Mikeysee

    Joined:
    Oct 14, 2013
    Posts:
    155
  9. Tim-C

    Tim-C

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    2,181
    Looks like a bug, can you raise a bug report please?
     
  10. Mikeysee

    Mikeysee

    Joined:
    Oct 14, 2013
    Posts:
    155
    Sure
     
  11. Mikeysee

    Mikeysee

    Joined:
    Oct 14, 2013
    Posts:
    155
    Last edited: Sep 16, 2014
  12. ITIProd

    ITIProd

    Joined:
    Nov 18, 2012
    Posts:
    14
    Any update on this bug? I'm suffering from the same issue...
     
  13. phil-Unity

    phil-Unity

    Unity UI Lead Developer Unity Technologies

    Joined:
    Nov 23, 2012
    Posts:
    1,226
    according to our bug database no nothing has been done about this yet.
     
  14. infinitypbr

    infinitypbr

    Joined:
    Nov 28, 2012
    Posts:
    3,149
  15. Mikeysee

    Mikeysee

    Joined:
    Oct 14, 2013
    Posts:
    155
    This got fixed in one of the late betas of 4.6, it works fine for me now.
     
  16. rakkarage

    rakkarage

    Joined:
    Feb 3, 2014
    Posts:
    683
    Code (CSharp):
    1. var p1 = UnityEngine.Camera.main.ScreenToWorldPoint(Vector3.zero);
    2. var p2 = UnityEngine.Camera.main.ScreenToWorldPoint(Vector3.right);
    3. unit = Vector3.Distance(p1, p2);
    can anyone explain what this code is for and why my orthographic 2d camera pan does not work without multiplying delta by this 'length of a unity vector'?

    it works and that is great but took me a while to 'figure it out'

    thanks