I created a new Unity project and installed the package for the new Input system. Basically I just want to store the position of a click (desktop) / tap (mobile), that's it.
I know the old system provides solutions
- https://docs.unity3d.com/ScriptReference/Input-mousePosition.html
- https://docs.unity3d.com/ScriptReference/Touch-position.html
but I want to solve it with the new input system.
I started with this input map configuration (I will show the configuration for each selected item)
I created a new script logging each click/tap position
public class FooBar : MonoBehaviour
{
public void Select(InputAction.CallbackContext context)
{
Vector2 selectPosition = context.ReadValue<Vector2>();
Debug.Log($"Select position is: {selectPosition.x}|{selectPosition.y}");
}
}
In the scene I created an empty gameobject and configured it in the inspector
Unfortunately when running the playmode I get these errors each time when moving the mouse around
This is the stacktrace of the first error message
and this is the stacktrace of the second error message
So I'm assuming my input map configuration is wrong.
Would someone mind helping me setting up an input configuration passing the click/tap position to the script?
So for a quick workaround I currently use this code with the old input system but I really don't like it ;)
public sealed class SelectedPositionStateController : MonoBehaviour
{
private void Update()
{
#if UNITY_ANDROID || UNITY_IOS
if (UnityEngine.Input.touchCount > 0)
{
Touch touch = UnityEngine.Input.GetTouch(0);
// do things with touch.position
}
#elif UNITY_STANDALONE
if (UnityEngine.Input.GetMouseButtonDown(0))
{
// do things with Input.mousePosition
}
#endif
}
// !!! USE THIS CODE BECAUSE IT'S OBVIOUSLY BETTER !!!
//
// public void SelectPosition(InputAction.CallbackContext context)
// {
// Vector2 selectedPosition = context.ReadValue<Vector2>();
//
// // do things with selectedPosition
// }
}


















