- Home /
New Input System OnMouseDown() Alternative
I updated my game to the new Input System and now the functions like OnMouseDown, OnMouseUp, OnMouseEnter, etc... don't work anymore. How can I get around this?
Answer by vanderFeest · Oct 14, 2020 at 01:42 PM
Make sure you have a an EventSystem
with an InputSystemUIInputModule
in the scene and a PhysicsRaycaster
or Physics2DRaycaster
on your Camera
, and then use the IPointerClickHandler
interface on the object with a collider on itself or its children:
using UnityEngine;
using UnityEngine.EventSystems;
public class MyClass : MonoBehaviour, IPointerClickHandler {
public void OnPointerClick (PointerEventData eventData)
{
Debug.Log ("clicked");
}
}
Answer by Marioooo · Sep 09, 2020 at 03:22 PM
On new Input system, create a new control scheme for keyboard and mouse (if you pretend to support some other input types). Then create an action map and an action. set type to button and on binding, click "Listen", then perform a right click and select it. Now, this is setup for onMouseDown right as it is... so you shouldn't have any issue with that... for other types of interactions, on submenu "Interactions" click on sign "+" and on the new interaction panel, select "press" for holding and "Release only" for mouse release.
IMPORTANT NOTE: i had some issues with player input component, those interactions doesn't work and overall has some problems... so the workaround i found is to subscribe to the event programmatically instead of using the playerInput component. Hope this helps!
Listening for mouse clicks isn't the problem. The method On$$anonymous$$ouseDown() is called when I click on a object with collider attatched (it works like the interface IOnPointerDownHandler but for colliders instead of UI elements).
This actually doesn't work. Using a mouse pointer as an action triggers when the mouse is clicked ANYWHERE in the scene. Having On$$anonymous$$ouseDown on an collider only triggers when you click that specific collider.
Your answer

Follow this Question
Related Questions
Help In Making a SphereCast for 3D Tire! Working RayCast Script included! 0 Answers
Check where mouse is clicked 1 Answer
Is there a built in method that works like OnMouseDown() but for touch input? 1 Answer
GUITexture and GameObject OnMouseDown() Problem 1 Answer
How to detect when the mouse button is being held down while the cursor is inside a collider? 1 Answer