Search Issue Tracker

Fixed in 4.6.X

Votes

2

Found in

4.6.0b18

Issue ID

633826

Regression

No

UI InputField's with content size fitter caret is misaligned when pivot is altered

UI

-

To reproduce this bug:

1. Open the attached project
2. Open scene "CSF Input."
3. Play the scene
4. Click on the input field and start typing
5. Note how the input text caret is not aligned with the end of the text
6. Stop, select the "Input Field" object in the inspector
7. Change the X pivot of this object's RectTransform to 0.5
8. Play again, now caret aligns correctly

Comments (9)

  1. joshstiemsma

    Nov 30, 2020 17:57

    this was not fixed still.... when resizing the rect of a name field the caret was messing up. These scripts you guys provided helped a ton!

  2. BlueTea

    Jul 30, 2015 15:06

    This bug is confirmed in 5.1.1 and 5.1.2. All scaled inputField have this behaviour. This is an absolutely unacceptable bug, yet probably so simple to fix.

  3. Wenamun

    Jul 17, 2015 13:13

    This error seems to be back in full force. My UI carets were aligned beautifully before I updated to 5.1. now they're all showing up below the actual character by about a whole character's height.

  4. Fattie

    Jun 29, 2015 07:45

    Sigh -- sorry my code below I forgot a line:

    using UnityEngine;
    using UnityEngine.UI;
    using UnityEngine.EventSystems;

    public class CaretStick:MonoBehaviour, ISelectHandler
    {
    private bool alreadyFixed;
    public void OnSelect(BaseEventData eventData)
    {
    if (alreadyFixed) return;

    RectTransform caretTransform = (RectTransform)transform.Find(gameObject.name+" Input Caret");
    if(caretTransform == null) return;

    caretTransform.Translate(Vector3.up * 10f);
    caretTransform.Translate(Vector3.right * 5f);

    alreadyFixed = true;
    }
    }

  5. Fattie

    Jun 29, 2015 07:31

    Here's a trivial script that fixes it, for sure. Just setting the values manually for your project. Just attach this to each InputField. Set the values as you wish.

    using UnityEngine;
    using UnityEngine.UI;
    using UnityEngine.EventSystems;

    public class CaretStick:MonoBehaviour, ISelectHandler
    {
    public void OnSelect(BaseEventData eventData)
    {
    RectTransform caretTransform = (RectTransform)transform.Find(gameObject.name+" Input Caret");
    if(caretTransform == null) return;

    caretTransform.Translate(Vector3.up * 17f);
    caretTransform.Translate(Vector3.right * 5f);
    }
    }

  6. Thom_Denick

    Jun 27, 2015 03:50

    That code fix didn't work for me. I needed to manually offset because if I matched the text transform, the font size was throwing off the Caret quite a bit. Here's some code to position the Caret to a custom value.

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

    [RequireComponent(typeof(InputField))]
    public class CaretFix : MonoBehaviour {

    public float caretOffset = 20f;

    public void OnCaretFix()
    {
    InputField ipFld = this.gameObject.GetComponent<InputField>();
    RectTransform caretTransform = (RectTransform)transform.Find(gameObject.name+" Input Caret");
    caretTransform.Translate(Vector3.up * caretOffset);
    }
    }

  7. heskethgames

    May 23, 2015 16:52

    I am having the same issue too in Unity 4.6.5, would be lovely to get it fixed please.

  8. ColinN

    May 13, 2015 13:08

    I'm experiencing this problem in Unity 4.6.5. To work around it, I had to set my "Text" object's Y pivot to 0.9. It is now in roughly the right place.

  9. Orbcreation

    Sep 19, 2014 08:23

    It is possible to temporarily fix this with this code:
    using UnityEngine;
    using UnityEngine.UI;
    using UnityEngine.EventSystems;
    using System.Collections;

    public class FixInputFieldCaret : MonoBehaviour, ISelectHandler {

    public void OnSelect(BaseEventData eventData) {
    InputField ipFld = gameObject.GetComponent<InputField>();
    if(ipFld != null) {
    RectTransform textTransform = (RectTransform)ipFld.text.transform;
    RectTransform caretTransform = (RectTransform)transform.Find(gameObject.name+" Input Caret");
    if(caretTransform != null && textTransform != null) {
    caretTransform.localPosition = textTransform.localPosition;
    }
    }
    }
    }

Add comment

Log in to post comment

All about bugs

View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.