Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
1
Question by SleepDOTexe · Jun 03, 2016 at 02:39 PM · uiinputeventsystemmodules

Make Standalone Input Module ignore mouse input?

I have a system of buttons in a UI canvas, which are linked to an EventSystem using Standalone Input Module. By default, this module responds to Mouse and Keyboard Input. Mouse input can cause glitches with my UI and is unnecessary, so I would rather disable it. However the standalone Input Module seems to only have options for Keyboard only, Controller, and both Keyboard and Mouse; yet not Keyboard only.

How can I make the module ignore all mouse events? (Mouse hover, Mouse clicks, etc.)

Comment
Add comment
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

2 Replies

· Add your reply
  • Sort: 
avatar image
7

Answer by Vodolazz · Sep 24, 2016 at 11:03 AM

I had same problem which I've just solved. Unity provides their 2 inputModules as an out-of-the-box decision for most common tasks. (https://docs.unity3d.com/Manual/InputModules.html)

Basically, you can inherit your own type from BaseInputModule and write new input module realization specially for your needs. As far as I know, Unity suggests this method by itself, but you will need rather good skill and time to do it. There is an easier way.

Just inherit your class from StandaloneInputModule and override Process() method.

Here is the code ( If you are confused, just create new C# script, copypaste the code and use this script instead of input module):

 class OnlyKeyBoardInputModule : StandaloneInputModule
 {
     public override void Process()
     {
         bool usedEvent = SendUpdateEventToSelectedObject();
 
         if (eventSystem.sendNavigationEvents)
         {
             if (!usedEvent)
                 usedEvent |= SendMoveEventToSelectedObject();
 
             if (!usedEvent)
                 SendSubmitEventToSelectedObject();
         }
     }
 }

If you want to turn on and off mouse events, you can do the following:

 class OnlyKeyBoardInputModule : StandaloneInputModule
 {
     //variable to hold current settings
     private bool isMouseInputActive = false;
 
     //type interface to get actual mouse input status
     public bool GetMouseState
     {
         get { return isMouseInputActive; }
     }
 
     //mouse switcher interface 
     public void MouseSwitcher()
     {
         isMouseInputActive = isMouseInputActive == false ? true : false;
     }
 
     //inherited event processing interface (called every frame)
     public override void Process()
     {
         bool usedEvent = SendUpdateEventToSelectedObject();
 
         if (eventSystem.sendNavigationEvents)
         {
             if (!usedEvent)
                 usedEvent |= SendMoveEventToSelectedObject();
 
             if (!usedEvent)
                 SendSubmitEventToSelectedObject();
         }
 
         if (isMouseInputActive)
             ProcessMouseEvent();
     }
 }




Comment
Add comment · Show 2 · 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 mcarrascosh · Oct 23, 2018 at 04:38 PM 0
Share

Great answer! Perfectly solved my problems after days of searching around. And it's easy to implement as well! Just made my day

Only one thing: Be sure to include the line using UnityEngine.EventSystems; at the top of the script.

avatar image Sylon87 · Aug 04, 2020 at 03:24 AM 0
Share

really thank's you!

avatar image
0

Answer by idbrii · May 03, 2018 at 04:25 PM

The simple answer is ensure that your StandaloneInputModule doesn't call ProcessMouseEvent. Whether that's modifying your existing InputModule or implementing a new one (for both, see Vodolazz's answer).


However, another note: if anything is using GraphicRaycaster, it's probably building its own PointerEventData and ignoring your InputModule as demonstrated in the docs. You should either convert it to IPointerEnter/ExitHandler, skip update when using gamepad, or make it pass in PointerEventData.position = Vector2.zero (bottom-left corner of the screen) so it doesn't hover anything when using gamepad.

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

82 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

Related Questions

InputSystem no UI Events while Time.timeScale =0 1 Answer

Check if EventSystem is in InputField 1 Answer

Detect which prefab triggers the button UI 1 Answer

Unity 5.2 - How can I keep other players from using a menu? 0 Answers

Detect if mouse has clicked on a UI element? 0 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