Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
5
Question by v1ness · May 30, 2020 at 08:41 PM · inputonmouseenteronmouseexit

OnMouse events (e.g. OnMouseEnter) not working with new Input System

Hi,

I just figured out that OnMouse events (OnMouseEnter, etc.) are not working after adding the new input system. I wondered if this is a bug or a feature. If this is in case intended, could someone explain to me, why this is happening?

I tested it in several projects with this simple setup. Empty scene with only a Cube (box collider attached of course :)) and this simple script:

 using UnityEngine;

 public class Test : MonoBehaviour
 {
     private void OnMouseEnter()
     {
         Debug.Log("Test");
     }
 }

The result was always the same. It works perfectly before adding the new Input System but not after.

Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Sephyk2 · Jun 03, 2020 at 04:53 PM 0
Share

Hello same here. I got several cube with onmousenter script to display gameobject above them. With old system, was working fine. With new one not.

I tried to swap for IPointerEnterHandler.OnPointerEnter IPointerExitHandler.OnPointerExit

But that doesnt work, even a simple debug inside those method did not prompt. and i also need to reimplement On$$anonymous$$ouseDown as it do not work too with new system.

avatar image Tethera · Jun 05, 2020 at 10:28 PM 0
Share

I tried migrating to the new input system last week, and I'm having the exact same problems with no answers. I can't get any On$$anonymous$$ouse events to work. IPointers only work for me on UI images with the Raycast Target set to true. Using 2019.3.15f1.

2 Replies

· Add your reply
  • Sort: 
avatar image
4

Answer by KevinDW · Jul 29, 2020 at 09:22 AM

I was strugling with the same problem, but this excellent StackOverflow answer showed me the correct way of doing this. (Solution 6)



First, you need to add a PhysicsRaycaster to your camera. Once you have done that, you can implement the IPointerEnterHandler and IPointerExitHandler (and all the other ones) on any gameobject you like.

You can add a PhysicsRaycaster by adding the following script to your camera:

 public class MeshDetector : MonoBehaviour
 {
     void Start()
     {
         addPhysicsRaycaster();
     }
 
     void addPhysicsRaycaster()
     {
         PhysicsRaycaster physicsRaycaster = GameObject.FindObjectOfType<PhysicsRaycaster>();
         if (physicsRaycaster == null)
         {
             Camera.main.gameObject.AddComponent<PhysicsRaycaster>();
         }
     }
 }


Afterwards, you can use IPointerEnterHandler etc as such:

 public class MyGameObject : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler
 {
     public void OnPointerEnter(PointerEventData eventData)
     {
         Debug.Log("Hello - Mouse Enter");
     }
 
     public void OnPointerExit(PointerEventData eventData)
     {
         Debug.Log("Hello - Mouse Exit");
     }
 }

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by KanyeWestknight · Oct 30, 2021 at 08:54 AM

@v1ness

Don't know if you figured it out but I was searching for this exact topic and there never really was an answer to what to do that I could find. Tried refining searches a bunch but your question was one of the ones at the top of the search for "mouseover unity new input" and a bunch of variations of that including the IPointerEnterHandler search as well.


Here is what I was able to do to get the Vector2 dimensions with ease:

alt text alt text

and my current code to grab the Vector2 of the position (Which I am testing but putting it in FixedUpdate() seems to work well so far:

Vector2 mousePosition = mouseInput.Mouse.MousePosition.ReadValue<Vector2>();

I hope this helps either you or someone else that comes by with the same issues I was having when starting out with the new Input system.


untitled2.png (55.3 kB)
untitled.png (49.2 kB)
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

158 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Change cursor on OnTrigger 0 Answers

OnMouseDown 2 Answers

OnMouseEnter/Exit fail when Parent. [Solved] 0 Answers

OnMouseEnter when enabling a object 2 Answers

OnMouseOver Problem 3 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges