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?
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.
//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";
}
}
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.