Search Unity

  1. We are migrating the Unity Forums to Unity Discussions. On July 12, the Unity Forums will become read-only.

    Please, do not make any changes to your username or email addresses at id.unity.com during this transition time.

    It's still possible to reply to existing private message conversations during the migration, but any new replies you post will be missing after the main migration is complete. We'll do our best to migrate these messages in a follow-up step.

    On July 15, Unity Discussions will become read-only until July 18, when the new design and the migrated forum contents will go live.


    Read our full announcement for more information and let us know if you have any questions.

Question Get position for the "Click" event?

Discussion in 'Input System' started by mortoray, Aug 4, 2023.

  1. mortoray

    mortoray

    Joined:
    Sep 14, 2018
    Posts:
    94
    How do I properly get the position where an interface click event occurred?

    That is, in an InputActionMap I have the standard "Click" event as below.
    upload_2023-8-4_9-32-26.png

    I add a performed listener, but then want to know where it occurred. Right now I'm reading the current mouse position, which isn't correct since it might not be a mouse (could be pen/finger/other).
    ```
    void OnClicked(InputAction.CallbackContext context) {
    var position = Mouse.current.position.ReadValue();
    ```

    What's the right way to get the position at the time the "Click" action happened?
     
    DevDunk likes this.
  2. spiney199

    spiney199

    Joined:
    Feb 11, 2021
    Posts:
    8,647
  3. mortoray

    mortoray

    Joined:
    Sep 14, 2018
    Posts:
    94
    Yes, that'll appear to work. What I did now is to listen for `Point` input action as well, which is mapped from all the devices. I just store it in a variable as it happens.

    The ReadValue on a button action, like Click, is a float value about how much the button is pressed. For a mouse button this is either 0 or 1.
     
    DevDunk likes this.