Drag Drop System with New Input, First Pointer Position is always 0 Problem

Hi there,

Im trying to make a drag drop, and it works
However issue is first pointer position is always 0, but next call returns the right value, in the editor, which is problematic and i want to understand why its happening like this.

Here is my setup

My code where first p

            inputActions.Player.PointerPosition.performed += OnPointerPosition;

            inputActions.Player.PointerClick.started += OnPointerDown;
            inputActions.Player.PointerClick.canceled += OnPointerUp;

 private void OnPointerDown(InputAction.CallbackContext obj)
 {        
            lastMousePosition =  inputActions.Player.PointerPosition.ReadValue<Vector2>();
//its zero but next call will return actual player position
}

Please advise :pray:

My guess would be that PointerClick.started happens before PointerPosition has had a chance to update? I have no evidence for this and a brief look at the docs has no revealed anything.

Solutions I can think of from the top of my head are:

  • using performed also for the PointerClick action and seeing if that fixes the timing
  • doing your action on pointer up instead
  • doing your action in the first OnPointerPosition. This way you get the first position for one “movement”. You could then skip all other OnPointerPosition events until it gets reset in OnPointerUp

Hope any of these help

Edit: Fix typos