Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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
1
Question by mr-sambarlow · Apr 02, 2015 at 06:11 PM · guiinputfield

How to prevent Input Field firing End Edit on change of focus?

I have an input field that is using End Edit to fire off some logic. End Edit is triggered when the user pushes a real (or virtual, on mobile) Enter key -- which is as desired. However, if the player clicks in the input field and then clicks outside it (changing focus?) then End Edit fires also.

Is it possible to prevent it from firing when this happens -- or do detect this has happened, so I can ignore it?

--Sam

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
3

Answer by steakpinball · Apr 02, 2015 at 06:26 PM

It sounds like you should be using the OnSubmit event from the event system instead of EndEdit from the input field. Use it By adding an EventTrigger component to a game object and configuring your logic for a Submit event. Beware the submit event is fired on your object regardless of what currently has focus.

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 mr-sambarlow · Apr 03, 2015 at 12:07 AM 0
Share

Thanks $$anonymous$$!

avatar image mr-sambarlow · Apr 03, 2015 at 10:04 AM 0
Share

O$$anonymous$$ -- I tried this, but having problems with Submit. Similar to this

http://forum.unity3d.com/threads/onsubmit-doesnt-fire-on-inputfield.273645/#post-1959106

I have to hit ENTER twice to get the event to fire.

Further searching reveals a lot of people struggling with EndEdit/Submit -- the only "solution" I've seen is to use EndEdit but to test for the ENTER key being down to avoid firing on focus change. That sounds hacky!

avatar image
3

Answer by gresolio · May 27, 2017 at 09:56 PM

Simple solution:

 using UnityEngine;
 using UnityEngine.UI;
 
 public class CustomSubmit : MonoBehaviour
 {
     public InputField Field;
     private bool wasFocused;
 
     private void Update()
     {
         if (wasFocused && Input.GetKeyDown(KeyCode.Return)) {
             Submit(Field.text);
         }
 
         wasFocused = Field.isFocused;
     }
 
     private void Submit(string text)
     {
         Debug.Log("Submit=" + text);
     }
 }
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 heatseeker0 · Aug 24, 2017 at 03:37 PM 0
Share

Thank you. Works like a charm.

avatar image gresolio · Aug 24, 2017 at 07:28 PM 0
Share

You're welcome :)

Thanks for the kind words, now I feel better after not very good statements about this solution. Some people don't value the time of others at all.

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

WebGL build Japanese IME 0 Answers

Unity 4.6 InputFields need help 1 Answer

change GUI InputField to TMP_InputField 0 Answers

Terminal-like GUI, wait for input 1 Answer

Prevent to Deselect InputField 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