// code extracted from Update()
if (_isPointerEnabled)
{
// Added this line just to make sure that the Pointer action is enabled
// calls <input map instance>.Disable() to disable the whole action map
// then calls <input map instance>.Player.Pointer.Enable() to selectively enable the input action
GameInput.Enable(InputActions.PlayerPointer);
_pointerPlane = new Plane(socket.rightHand.forward, socket.rightHand.position);
// action.ReadValue<Vector2>() always returns (0.0, 0.0)
Vector2 pointerPosition = GameInput.Player.Pointer.ReadValue<Vector2>();
// added this line to compare the input action value with the current mouse value.
// seems to return the proper value
pointerPosition = UnityEngine.InputSystem.Mouse.current.position.ReadValue();
var ray = GameManager.cinemachineBrain.OutputCamera.ScreenPointToRay(pointerPosition);
if (_pointerPlane.Raycast(ray, out float enter))
{
Vector3 target = ray.GetPoint(enter);
_pointer.position = Vector3.MoveTowards(_pointer.position, target, Time.deltaTime*10);
}
}
(this image shows that even though the input action is enabled I get a default value (0.0, 0.0))
EDIT:
This snippet of code where call ReadValue() followed by Mouse.position.ReadValue() was an attempt to inspect what is wrong with my code and have a temporary workaround.
For production I need this code to work with different input schemes.
Yes, you are right. I want the mouse position on the current screen.
Got it! I’ve tried having Type “Value” and also tried “Pass Through” as it is what is being used by the default ‘UI/Point’ with no luck.
I’ve tried that too! Actually I’ve changed mine to ‘Position [Pointer]’ after reading in the documentation that Mouse is a Pointer with extra functionality. Is that not right? Should I change it back to Mouse?
I’m not using the Player Input component though. I’m instantiating and managing the action map myself. Also, on other parts of my code I’m reading Input Action values through ReadValue() just fine without the need for rising events. Can I do that with the mouse position as well?
here is a little snippet of code that already works for me:
// GameInput.cs
public static InputActionCollection Map => _map;
public static PlayerActions Player => _map.Player;
To clarify, I already have my input system laid down and working, and now I want to add a new InputAction bound to the current mouse position. I’ve configured and pulled the new InputAction value according to the documentation but somehow I’m getting only (0.0, 0.0).
I’ve tried to debug it but I couldn’t figure out what is wrong, everything looks to be setup right and when I step through the code I don’t see anything wrong. Am I missing something obvious here? Does this look a bug? Does this thread need more clarification?
The action map was disabled while the input action was enabled. This somehow caused my input actions to partially work. Like, they fire events but their Interactions wont have any effect and their values wont be read properly.
My solution was to rework my GameInput class in a way that the action maps are always enabled when at least one of its input actions are enabled.
Sorry for the necro-posting. I have the same problem, but somehow not understand how do you fixed.
I Either don’t use the player input evil class, and bind the input like you putting the reference in a static field and access from a generic InputManager class.
public class InputManager : MonoBehaviour
{
public static GameControls inputActions;
private void Awake()
{
// Create the game controls
inputActions = new GameControls();
// Make it permanent through scenes
DontDestroyOnLoad(gameObject);
}
private void OnEnable()
{
inputActions.Enable();
}
private void OnDisable()
{
inputActions.Disable();
}
}
I Have a strange problem with the mouse position. In shorts, i have the mouse position that and the left stick that handle the character looking. I handle the mouse position value convertion in this way:
In this order if i use the right stick, it works fine, and if swap to the mouse after it works fine. BUT if i switch out to the gamepad right stick again, it does not work anymore (Seems that the mouse still catch the input but does not call this event).