Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice
  3. Dismiss Notice

Bug Why the canceled callback can be invoked after performed?

Discussion in 'Input System' started by ZackYangbalabala, Oct 17, 2023.

  1. ZackYangbalabala

    ZackYangbalabala

    Joined:
    Oct 3, 2020
    Posts:
    6
    Hello guys:
    I'm new to the input system, and I'm not quite sure if this is a bug or not, I'm currently using Input System 1.4.4, with the touchscreen inputs.
    So I'm trying to make a "charged move" here, the player would need to hold the screen for a short period of time to charge, and then the "tank" will keep moving towards the player's finger location until the player lifts his/her finger from the screen.
    In order to do that, I created a PrimaryTouchDetection action to check whether the player is pressing on the screen.
    Code (CSharp):
    1.         _touchInput.Touch.PrimaryTouchDetection.performed += ctx => TouchDetection();
    2.         _touchInput.Touch.PrimaryTouchDetection.canceled += ctx => TouchUp();
    At first, I thought the performed and cancelled callback would just work as GetButtonDown and GetButtonUp, so once the player is holding the screen for enough time, the TouchDetection() will be called and the "Tank" will start to move to the player, and when the player is no longer pressing the screen, the TouchUp() will be called to reset everything.
    And everything just worked until today I checked the documentation again, and I found that the definition of the cancelled callback for Hold interaction is this :
    "Control magnitude goes back below pressPoint before duration (that is, the button was not held long enough)."
    So according to the documentation, the "cancelled" callback should never been invoked after the "performed", but why in my case it just "work as I expected"?
    And if this is a bug, what is the proper way to listen to the "Press" action ends?
     

    Attached Files:

  2. ZackYangbalabala

    ZackYangbalabala

    Joined:
    Oct 3, 2020
    Posts:
    6
    Alright, I think I need to make some clarification of what my question is.

    For "Hold" interaction, the definition for "Performed" callback is
    "Control magnitude held above pressPoint for >= duration."
    And for the "Cancelled" callback is
    "Control magnitude goes back below pressPoint before duration (that is, the button was not held long enough)."

    Basically, if the "Performed" callback is triggered, the "Control magnitude" has been held above the pressPoint for >= duration time, which means the Cancelled callback should never been invoked after this point of time, however, in my case, when I pressing the screen for enough time, the Performed callback would be triggered properly, but the Cancelled callback would also be triggered if I release my finger after this point.

    So is this a bug or not? And how should I fix this?
     
  3. TheFourthEye

    TheFourthEye

    Joined:
    Jan 5, 2021
    Posts:
    3
    Sorry for necro'ing this post, but I have to say this is my exact experience. Granted, I am actually looking for a drag that does something when I release, regardless of how long it's held, but that doesn't fit the definition in the manual. So what is the actual expected behavior, and if this isn't it, is it going to get patched and kill my current solution?