Unity UI 4.6 inputfield bug or behavoir?

I’m having problems with unity inputfields keep taking keyboard input after I have pressed return.

I have written three questions regarding this on unity answers but so far not got any positive replies.

The issue is:

Once an input field has been clicked on, and text entered. If it is then submitted by pressing enter or by clicking on another game object, if I then move my character controller around a bit the input field will keep picking up the WSDA keys or anything else I press.

Also, if there is more than one input field, the focus will randomly switch from one input field to another after I press submit or move around a bit.

The questions detailing this are here:

http://answers.unity3d.com/questions/867836/46-inputfield-strange-behaviour-after-submit.html

Please help this is really holding up my project.

Many thanks in advance.

If it is a bug please let me know.

Anyone? I’ve tried this on three separate computers and I get the same behavior. This is a rather major bug if there isn’t something simple I’m missing.

So is it a bug do I need to report it?

Enter doesn’t make the input field lose focus. Have you considered just disabling the input field? If you’re using WASD for movement I’m going to guess the input field is probably not on the screen or being used, yes? You can just do the InputField.enabled = false and then reenable it later if you want input to go in.

Basically what is happening is you aren’t switching to some other control so the input field is still taking in put. If you have multiple input fields it might be useful to have more than one submit button per field or one big submit button that just turns them all off when you’re done.

1 Like

The input fields are on a canvas in world space, and there are many of them floating above objects. However this bug also manifests on non world space inputfields if you have several on screen. Once you have clicked on one, when you press return it will just focus another one randomly. Go on try it.

Disabling them isn’t an option because I want them to be able to still be edited when someone clicks on one and I just want them to go back to the state they were in once someone has pressed return. I dont’ want to switch interactable to false because this means I won’t be able to click them again.

pressing enter just stops the editing it never deselects the graphic. If you want to deselect it, listen for the onsubmit event and then call EventSystem.current.SetSelectedGameObject(null);

That doesn’t appear to work please look at this code:

using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using UnityEngine.EventSystems;

public class CreateCanvasButton : MonoBehaviour {

void Start () {
// create event system
GameObject eventsystem = new GameObject ();
eventsystem.AddComponent ();
eventsystem.AddComponent ();
eventsystem.AddComponent ();

string name = “Canvas”;

GameObject newCanvasGO = new GameObject ();
newCanvasGO.name = name;
newCanvasGO.transform.SetParent (this.transform);
newCanvasGO.AddComponent ();
newCanvasGO.AddComponent ();
newCanvasGO.AddComponent ();

RectTransform theCanvasRectTransform = newCanvasGO.GetComponent ();
theCanvasRectTransform.anchoredPosition3D = new Vector3 (0f, 0f, 0f);
theCanvasRectTransform.sizeDelta = new Vector2 (2400f,3800f);
theCanvasRectTransform.anchorMin = new Vector2 (0f,0f);
theCanvasRectTransform.anchorMax = new Vector2 (1f,1f);
theCanvasRectTransform.localScale = new Vector3 (0.0005f,0.0005f,1f);
theCanvasRectTransform.localPosition = new Vector3 (0f, 2.9f, 0f);
Canvas theCanvas = newCanvasGO.GetComponent ();
theCanvas.worldCamera = Camera.main;
newCanvasGO.SetActive (true);
newCanvasGO.AddComponent ();
Image canvasImage = newCanvasGO.GetComponent ();
Sprite mySprite = Resources.Load (“Background”);
canvasImage.sprite = mySprite;
canvasImage.type = Image.Type.Sliced;
// create name title text
GameObject titleTextGO = new GameObject ();
titleTextGO.name = “Name_text”;
titleTextGO.transform.parent = newCanvasGO.transform;
Text titleText = titleTextGO.AddComponent ();
RectTransform titleTextRT = titleTextGO.GetComponent ();
titleTextRT.anchoredPosition3D = new Vector3 (0f,0f,0f);
titleTextRT.sizeDelta = new Vector2 (877,199);
titleTextRT.localPosition = new Vector3 (-22f,1722f,0f);
titleTextRT.localScale = new Vector3 (1f, 1f, 1f);
titleText.text = “Title”;
Font theFont = Resources.GetBuiltinResource (“Arial.ttf”);
titleText.font = theFont;
titleText.fontSize = 140;
titleText.color = Color.black;
titleText.alignment = TextAnchor.MiddleCenter;
titleText.resizeTextForBestFit = true;
titleText.resizeTextMinSize = 10;
titleText.resizeTextMaxSize = 160;
// create nickname title text
GameObject TextGO = new GameObject ();
TextGO.name = “InputField”;
TextGO.transform.parent = newCanvasGO.transform;
TextGO.AddComponent ();
RectTransform TextRT = TextGO.GetComponent ();
TextGO.AddComponent ();
InputField myInput = TextGO.GetComponent ();
TextRT.anchoredPosition3D = new Vector3 (0f,0f,0f);
TextRT.sizeDelta = new Vector2 (1669,3370);
TextRT.localPosition = new Vector3 (-35f,-188f,0f);
TextRT.localScale = new Vector3 (1f, 1f, 1f);
myInput.transition = Selectable.Transition.None;
myInput.text = “SomeText that never appears”;

myInput.onEndEdit.AddListener(delegate{StopInput(myInput);});

GameObject textForInputGO = new GameObject ();
textForInputGO.name = “Text_ForInputField”;
textForInputGO.transform.SetParent(TextGO.transform);
RectTransform textRT = textForInputGO.AddComponent ();
Text textscript = textForInputGO.AddComponent();
textRT.sizeDelta = new Vector2 (1356f,300f);
textRT.localPosition = new Vector3 (0f,-0f,0f);
textRT.localRotation = new Quaternion (0f, 0f, 0f, 0f);
textRT.localScale = new Vector3 (1f,1f,1f);
myInput.textComponent = textscript;
textscript.supportRichText = false;
textscript.resizeTextForBestFit = true;
textscript.resizeTextMaxSize = 300;
textscript.resizeTextMinSize = 10;
textscript.font = theFont;
textscript.text = “This is the main body text.”;
textscript.color = Color.black;
textscript.alignment = TextAnchor.MiddleCenter;

// create button
GameObject invisibleButtonGO = new GameObject ();
invisibleButtonGO.name = “invisibleButton”;
invisibleButtonGO.transform.parent = newCanvasGO.transform;
invisibleButtonGO.AddComponent ();
RectTransform invisibleButtonRT = invisibleButtonGO.GetComponent ();
invisibleButtonRT.anchoredPosition3D = new Vector3 (0f,0f,0f);
invisibleButtonRT.sizeDelta = new Vector2 (358,354);
invisibleButtonRT.localPosition = new Vector3 (1021f,-1723f,0f);
invisibleButtonRT.localScale = new Vector3 (1f, 1f, 1f);
invisibleButtonGO.AddComponent ();
Button invisibleButton = invisibleButtonGO.GetComponent ();
invisibleButton.transition = Selectable.Transition.None;
invisibleButton.onClick.AddListener (() => handleButton());

//add image for ray casting invisable button:
Image image = invisibleButtonGO.AddComponent();
image.color = new Color(0, 0, 0, 0);

}

void handleButton (){
print (“pressed!”);
}

void StopInput(InputField _input) {
print (_input.text);
EventSystem.current.SetSelectedGameObject(null); // neither does this
}

}

  1. If I select another object rather than pressing return I get “Attempting to select while already selectring an object” error.

AND

  1. It requires me to press return twice before it stops accepting input.

Any ideas ?

I’d file a bug report and we can take a better look, i dont see anything wrong with the code.

Bug report submitted.

Phil, since this is timely, I thought I should ask here. I have a similar problem. When I select the text of an input field via script, that input field is then selected until a player deselects it by clicking elsewhere. Is that the correct default behavior?

What I am trying to do is have the player click a button that fills in the input fields that are onscreen, then use WASD to walk around while those input fields are still available for them to use if they want to eventually change their selection. I am currently using the solution you suggest to deselect the UI items through the event manager, but I’m wondering if there is a good reason for this being the default when an input field is edited via script.

well its the same behaviour as all other components its just visible with input field. pressing a button selects it, you will only get the deselect when you navigate away or press something else.

Changing the text of a input field via script shouldn’t activate it. so i’m not sure what your refering to.

I am saying that changing the text via script does seem to activate it 4.6.1f1 for me. If I call EventSystem.current.SetSelectedGameObject(null) after I change the text field in the script it will not record WASD as I move. But if I do not call that, it will record my keystrokes even if I never select the input field in the game (only via the script that changed the value of the text).

interesting could you file a bug on that, quick look at the code doesnt seem like it should activate but maybe something weird is going on.

Have you had a chance to look at my bug report yet ?

I dont know which is yours, and they always go through QA to verify first. So i’m guessing no.

I submitted a bug report for my issue. #662033

What’s the point submitting bugs? They never fix them.

1 Like

I hope they will look at this inputfield bug/behavior because I’ve been dealing with this for 4 weeks now and its really holding up my project.

1 Like

Looking forward to resolution of the inputfield issues.

Just while you wait to process the bug report you can re-create these issues by adding multiple inputfields into a blank scene and then adding in a plane with collider and First Person Controller to move around.

Then just trying clicking on one input field and then press return and move around a bit. You’ll see what I’m taking about.