Search Unity

Change InputField Caret

Discussion in 'UGUI & TextMesh Pro' started by Marble, Sep 19, 2014.

  1. Marble

    Marble

    Joined:
    Aug 29, 2005
    Posts:
    1,268
    Can the InputField text caret be changed / animated? I'd really like to turn it into a feather quill with a bit of rotation noise around the tip when typing.
     
  2. phil-Unity

    phil-Unity

    Unity UI Lead Developer

    Joined:
    Nov 23, 2012
    Posts:
    1,226
    Currently no it cant be changed. Your have to duplicate the input field and change the GenerateCursor functionality.
     
  3. Orbcreation

    Orbcreation

    Joined:
    May 4, 2010
    Posts:
    231
    Uhmm... The inputField does create a child RectTransform for the caret. I capture this to get around a bug that occurs when the pivot of the inputfield is changed http://issuetracker.unity3d.com/iss...ter-caret-is-misaligned-when-pivot-is-altered. Like this
    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.UI;
    3. using UnityEngine.EventSystems;
    4. using System.Collections;
    5.  
    6. public class FixInputFieldCaret : MonoBehaviour, ISelectHandler {
    7.  
    8.     public void OnSelect(BaseEventData eventData) {
    9.         InputField ipFld = gameObject.GetComponent<InputField>();
    10.         if(ipFld != null) {
    11.             RectTransform textTransform = (RectTransform)ipFld.text.transform;
    12.             RectTransform caretTransform = (RectTransform)transform.Find(gameObject.name+" Input Caret");
    13.             if(caretTransform != null && textTransform != null) {
    14.                 caretTransform.localPosition = textTransform.localPosition;
    15.             }
    16.         }
    17.     }
    18. }
    19.  
    Would't it be possible to change this code and add an Image component to the gameobject I found for the Input Caret?
     
  4. phil-Unity

    phil-Unity

    Unity UI Lead Developer

    Joined:
    Nov 23, 2012
    Posts:
    1,226
    Not really ATM removing that GO would cause a null as the input expects it to be there.
     
  5. Marble

    Marble

    Joined:
    Aug 29, 2005
    Posts:
    1,268
    Funny. I reported that bug, so it looks like I got something out of this thread after all. Thanks @Orbcreation !

    I tried adding an Image to the caret GO as postulated, and it did appear, but the Image became invisible on further input. Tweaking the Image in the inspector in any way makes it visible again. So does switching to a different app and back to Unity. I've experimented with several ways to trigger this in a script, but can't seem to do it. Neither Graphic.SetAllDirty() nor Graphic.Rebuild() produce the same effect. But it feels like there might be a workaround here.

    Of course, it would be great to have this officially supported.
     
    Last edited: Sep 19, 2014