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 /
avatar image
1
Question by rbbrdckybk · Aug 04, 2011 at 06:25 PM · inputgetkeydown3.4

Input.GetKeyDown bug introduced with 3.4?

I have a simple chat client project that would build and run with no issues in Unity 3.3. I recently installed Unity 3.4, and went back to the project today. It builds and runs, but I noticed something strange - Input.GetKeyDown does not seem to be working at all for me. Here is the code:

 void Update()
 {
     if (Input.GetKeyDown("return"))
     {
         SendChatMessage();
     }
 }


SendChatMessage() is never called. I added Debug.Log() statements immediately before the Input check, and within the if block - Update() is being called properly, but the GetKeyDown call never returns true.

I've tried Input.GetKeyDown(KeyCode.Return) and Input.GetKeyDown("enter"). Neither work. I even tried some other keys - none of them respond to keyboard input.

Again, this same code worked properly in 3.3. AFAIK, absolutely nothing has changed. Any ideas?

Comment
Add comment · Show 4
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 TheDarkVoid · Aug 04, 2011 at 06:28 PM 0
Share

try using Input.Get$$anonymous$$eyUp()

avatar image rbbrdckybk · Aug 04, 2011 at 06:37 PM 0
Share

Sorry, should have mentioned that I tried that too. Doesn't work.

avatar image TheDarkVoid · Aug 04, 2011 at 06:41 PM 0
Share

check the input manager

avatar image MacMac098 · Aug 04, 2011 at 06:49 PM 1
Share

use keycode void Update() { if (Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.return)) { SendChat$$anonymous$$essage(); } }

3 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by rbbrdckybk · Aug 04, 2011 at 06:46 PM

I just found the issue by commenting out code piece by piece. For some reason, when I commented out my OnGUI() method, input started working again.

I do have some async socket calls (it's a chat client), and I know some wonky things can happen if you're not careful to leave Unity objects alone outside of the main thread, so I assume that I wasn't careful enough and the issue is related to threading somehow.

Odd that this worked perfectly in 3.3, though.

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 rbbrdckybk · Aug 04, 2011 at 07:07 PM 0
Share

The issue actually ended up being that Input.Get$$anonymous$$eyDown no longer works when a GUI.Textfield has focus in Unity 3.4. In 3.3, that was not the case. Wish changes like this were documented.

avatar image Bunny83 · Aug 04, 2011 at 08:52 PM 0
Share

That's actually great news :D I've missed that feature all the time. You always needed some kind of workaround to detect that you're focusing a textfield and manually "ignore" the normal input.

avatar image
1

Answer by Bunny83 · Aug 04, 2011 at 08:54 PM

I've just looked up the Update news and i've found the change ;)

Input.eatKeyPressOnTextFieldFocus

That's what you need ;)
It's even already in the documentation: Input.eatKeyPressOnTextFieldFocus

See the update page / Other Improvements (near the end)

Input.eatKeyPressOnTextFieldFocus added to be able to control input behavior during textfield focus. This is default true from 3.4 and forth. Set this to false to achieve pre 3.4 behavior.

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 rbbrdckybk · Aug 04, 2011 at 09:11 PM 0
Share

Ah, thanks - I completely missed that. That actually makes a lot of sense. $$anonymous$$y workaround was going to be something like this in OnGUI():

         Event e = Event.current;
         if (e.is$$anonymous$$ey && e.keyCode == $$anonymous$$eyCode.Return)
         {
             SendChat$$anonymous$$essage();
         }

... but your solution is better.

avatar image Bunny83 · Aug 05, 2011 at 10:02 AM 0
Share

If the Textfield is in OnGUI it actually makes more sense to use the Event class. Your "workaround" is actually the best solution ;).

The Input class is for game input and only works in Update.

btw. is$$anonymous$$ey is true for both : $$anonymous$$eyup and $$anonymous$$eydown so your function will be executed twice.

 if (e.type == EventType.$$anonymous$$eyDown && e.keyCode == $$anonymous$$eyCode.Return)
 {
     SendChat$$anonymous$$essage();
 }

that would be the equivalent to Input.Get$$anonymous$$eyDown

avatar image
0

Answer by Graham-Dunnett · Aug 04, 2011 at 06:50 PM

This worked for me:

 //javascript
 var s : String = "hello";
 
 function OnGUI () {
 
     if (GUI.Button(Rect(10,70,150,30),s)) {
         s = "world";
     }
 
 }
 
 function Update () {
     if (Input.GetKeyDown("return"))
     {
         s = s + "x";
     }
 }
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

6 People are following this question.

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

Related Questions

Change view if key is pressed 4 Answers

error CS0117: `Input' does not contain a definition for `GetKeyDown' 1 Answer

Problem With else if statement 1 Answer

Why is GetKeyDown returning false when provided with string from .inputString? 2 Answers

Enter/Exit Vehicle with the same key? 2 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