[5.2] Caret missing in InputField (even in the default one)

The caret is always missing in our InputFields since the update to Unity 5.2. The caret object is still created by the InputField and contains the usual Canvas Renderer and Layout Element components, but it simply doesn’t show up.

We can write text just fine, and even select portions, but we cannot see them or where we are writing. If we create a default Input Field from UI > Input Field, it has the same problem.

Adding an Image component to the caret in Play mode (we tested that manually through the inspector) makes it show up and work as normal. When it shows it still fills the whole text field, but then resizes to normal after we select the field.

(This question shows the same problem.)

We assume this is a bug with this release. What can we do? What has changed in order to cause this? The release notes couldn’t give us a clue (maybe something to do with UI rendering?).

Thanks!

1 Like

Yes this is a bug that we caught to late i’m working on getting the fix into the first patch right now.

The issue is the caret needs to specify a texture to use. Give me a min i’m writing a script to help for now

Yep. I just noticed this. Glad its confirmed a bug, was blowing my mind.

This is dirty but works. The issue is before we would use a white texture if null was specified. This was removed so we now need to specify it to be a white texture (as done here). We are sad it was missed until earlier this week.

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

public class SetInputFieldTexture : UIBehaviour{

    public InputField inputField = null;

    IEnumerator Start ()
{
        // wait a frame such that the caret GO gets created.

        yield return null;
        if (inputField == null)
            inputField = GetComponent<InputField>();

       if (inputField != null)
       {
           // Find the child by name. This usually isnt good but is the easiest way for the time being.
           Transform caretGO = inputField.transform.FindChild(inputField.transform.name + " Input Caret");
           caretGO.GetComponent<CanvasRenderer>().SetMaterial(Graphic.defaultGraphicMaterial, Texture2D.whiteTexture);
       }
    }
}
4 Likes

Thanks for the fix. In the meantime I had created something very similar that also waits one frame and them adds an Image component to the caret (I guess the caret gets the texture from the Image in that case). It also works (as a “dirty hack”). :slight_smile:

yea i think my way might be better as the image will also want to control the verts of the caret where as the InputField is the one that needs sole control. Not saying your way doesnt work (as obviously it does) but there might be edge cases if the image tries to update the verts itself.

OK, thanks, I’ll keep that in mind and maybe change it tomorrow.

Any eta on when this patch will appear, or a more robust way of handling the issue than a yielding Start() method? We have lots of inputFields that are procedurally created at run time, which means they don’t exist when the containing behavior’s Start() method is called. We also have manually placed inputFields that are disabled at start, which means their caret objects don’t get created on the first frame of the parent behavior’s existence. I tried dropping your test-and-set-the-material code into the Update method of the behavior responsible for the inputFields in hopes of working around these creation timing issues but the inputField appeared to ignore the material changes.

I’m not sure, the fix has been pushed to the sustained engineering team to get it out to a patch release. I’m not sure which one it will get into.

As for another function off hand no but moving it to the Update should work just as well.

Should be fixed in 5.2.1p1 i think

Did you mean 5.2.0p1, that was released last week or actually 5.2.1p1, which will be released sometime in the future? I couldn’t find anything regarding the input caret in the patch notes…

1 Like

might be for a later one, I’m confused as to which release it made it to.

I updated to 5.2.1f1 today and this problem has only gotten worse. I created a new project, put a input field on a canvas, and no caret or highlight.

Unity, what’s going on? I really need an input field that works!

I would be happy to send in my example project.

BTW, a very big thanks to phil-Unity as his workaround still works!

I am using 5.2.1f1 as well and all of my input fields are messed up. I hope for a fix soon.

Should be out later this week.

I’m on 5.2.1p1, and the caret is there, but the position is wrong, if the text is not aligned at the top.

This fix does not work for me. Possibly because I am in World Space for the UI Canvas.

Does anyone have another work around?

1 Like

Grab p3 its been fixed.

I just installed p4, I am still seeing the issue though.

I get inconsistent results where I’ll have multiple fields that are configured exactly the same. Some will work and others will not. I will have to delete them and re-create them and sometimes they will work again.

Also, if I create a Prefab out of my form with Input Fields and then instantiate at some point while running, the caret does not work at all. Is anyone still having this issue?

Well, I’m using 5.2.1f1, which I assume the p4 is for the Pro Version. So maybe it’s broken in the Free Version?