Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Move Event not working correctly in the new Input System?

Discussion in 'Input System' started by The_MrX_, Mar 3, 2020.

  1. The_MrX_

    The_MrX_

    Joined:
    Aug 25, 2019
    Posts:
    12
    Basically, using the below code I am able to click and drag items in the old Input system, without any issues.It stays accurate to the cursor location.

    But It doesn't seem to work with the new Input System. It moves very slightly, but not accuratly to the amount the mouse is moving.

    At first I thought I'd just need to set the Move Event to the Player/Look binding, so that the event delta would be based on the mouse movement. But for some reason it only worked once...then it stopped working completely for all future attempts.
    That was in 2019.3.0f3

    So I tried it in 2019.3.3f1, 2019.3.0f6, both had the same problem.

    If you want to test it yourself
    > simply download a Unity version that supports the new Input system
    >make a new project
    > download the New Input system from the package manager
    > switch to the new Input system
    > Make some panels of a set size to drag around
    > add the script to the panel
    >Add the canvas to the script's canvas slot in the editor
    > Replace the Old Input Event Input system component on the EventSystem GameObject with the new one via the button that appears on the old Event Input Component.
    > Set the Move Event to player / look, so it's based on the pointer delta.
    > Then press play and try to drag it.

    https://i.imgur.com/h30t3Qf.png

    https://i.imgur.com/KfD13Vs.png


    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.EventSystems;
    3.  
    4. public class Dragable : MonoBehaviour, IPointerDownHandler, IDragHandler, IBeginDragHandler, IEndDragHandler
    5. {
    6.     private RectTransform _rectTransform;
    7.  
    8.     [SerializeField]private Canvas _canvas;
    9.  
    10.     private void Awake()
    11.     {
    12.         _rectTransform = GetComponent<RectTransform>();
    13.     }
    14.  
    15.     public void OnDrag(PointerEventData eventData)
    16.     {
    17.         _rectTransform.anchoredPosition += eventData.delta / _canvas.scaleFactor;
    18.     }
    19.  
    20.     public void OnBeginDrag(PointerEventData eventData)
    21.     {
    22.      
    23.     }
    24.  
    25.     public void OnEndDrag(PointerEventData eventData)
    26.     {
    27.      
    28.     }
    29.  
    30.     public void OnPointerDown(PointerEventData eventData)
    31.     {
    32.      
    33.     }
    34. }
    35.  
     
    Last edited: Mar 3, 2020
  2. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,227
  3. roulinade

    roulinade

    Joined:
    Feb 8, 2017
    Posts:
    3