Get position for the "Click" event?

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.

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?

1 Like

Use the general pointer class instead? Class Pointer | Input System | 1.6.3

Though I wonder the the CallbackContext.ReadValue returns on a pass through.

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.

1 Like