New Events System Issue when Panning Camera..

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.

1772907--112393--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:

1772907--112391--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: Dropbox - Error - Simplify your life

Cheers for any advice,
Mike

1 Like

Try adding Canvas.ForceUpdateCanvases after you have moved the canvas.

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.

No one have any ideas? Is there a way to change the order in which the events are processed? Or is this a bug?

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.

Good point :slight_smile: Worst comes to the worst ill manually implement panning / zooming without using the new events system.

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

Nope, pixel perfect is not on. I have created this stripped-down project which shows the problem:

https://www.dropbox.com/s/yoxw0e6tbbu87ii/UIJiterProblem.zip?dl=0

Looks like a bug, can you raise a bug report please?

Sure

Okay, I have sent a bug via the unity bug reporter: http://fogbugz.unity3d.com/default.asp?633562_q5q2soe3ehh3pt87

Any update on this bug? I’m suffering from the same issue…

according to our bug database no nothing has been done about this yet.

I have a very similar issue. Knowing it’s a bug is kind of a good thing, sort of, since when it’s fixed it should work. hopefully :smile:

This got fixed in one of the late betas of 4.6, it works fine for me now.

var p1 = UnityEngine.Camera.main.ScreenToWorldPoint(Vector3.zero);
var p2 = UnityEngine.Camera.main.ScreenToWorldPoint(Vector3.right);
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