Search Unity

PointerEventData.worldPosition always return (0, 0, 0)

Discussion in 'UGUI & TextMesh Pro' started by Percy-Tse, Aug 22, 2014.

  1. Percy-Tse

    Percy-Tse

    Joined:
    Aug 22, 2014
    Posts:
    10
    Hi,

    I have setup a Screen Space - Camera Canvas. When I try to access PointerEventData.worldPosition from a MonoBehaviour that implements IPointerClickHandler interface, it always return (0, 0, 0). Is that work as expected?

    In my case, I have two buttons from same parent, a Floor button and a Player button. When Floor button is clicked, Player button will move to clicked position. What is the best way to transform the position from PointerEventData? Thanks.
     
    rakkarage likes this.
  2. Tim-C

    Tim-C

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    2,225
    Hi, so there isn't really a 'valid' world position value for a screen canvas click. It's just a 2d location.

    What you do have is access to the Vector2 PointerEventData.pressPosition. Use this to move the button to the correct location as a screen canvas is (normally) in a 2d plane.
     
    rakkarage likes this.
  3. Percy-Tse

    Percy-Tse

    Joined:
    Aug 22, 2014
    Posts:
    10
    Got it. Thanks Tim.