Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice
  4. Dismiss Notice

TextMeshPro Caret RayCast Target

Discussion in 'UGUI & TextMesh Pro' started by Robdon, Dec 5, 2017.

  1. Robdon

    Robdon

    Joined:
    Jan 10, 2014
    Posts:
    141
    I know most components of TMP have a 'Raycast Target' flag we can unset if we need to.

    But, with the InputField type, there is a 'caret' that is created at runtime, that has 'Raycast Target' turned on, and there is no reference to this object, so I could disable it etc, or I couldn't find any type of setting in the inspector to get it to create the caret without it, since the caret seems to be created on the fly with no template anywhere I can find.

    Is there any possibility of having a setting for this or something, so that I can control the flag on carets?

    Thanks, Rob.
     
  2. Stephan_B

    Stephan_B

    Unity Technologies

    Joined:
    Feb 26, 2017
    Posts:
    6,588
    Out of curiosity, what is the use case for disabling or even having raycast enabled on the caret?
     
  3. Robdon

    Robdon

    Joined:
    Jan 10, 2014
    Posts:
    141
    I'm trying to disable it, so that I can have my own script on it can implement IPointerClickHandler.

    I'm trying to 'color' a box that is around the textfield when it has focus, so I need to know when its been clicked, but the caret it taking the 'click'.
     
  4. Stephan_B

    Stephan_B

    Unity Technologies

    Joined:
    Feb 26, 2017
    Posts:
    6,588
    Since the Caret inherit from MaskableGraphic, by default the Raycast is enabled. However, I can disable that by default given I don't think anyone would ever need to Raycast against the caret itself.

    You should be able to get a reference to the caret possibly using FindObjectOfType and set raycastTarget = false on it.
     
  5. Robdon

    Robdon

    Joined:
    Jan 10, 2014
    Posts:
    141
    Yeah, I thought of doing a find, just don't like using Find for 'real' things due to the performance ;)
     
  6. Stephan_B

    Stephan_B

    Unity Technologies

    Joined:
    Feb 26, 2017
    Posts:
    6,588
    Can you think of any reasons to have Raycast target enabled on the caret?
     
  7. methos5k

    methos5k

    Joined:
    Aug 3, 2015
    Posts:
    8,712
    I don't recall ever "clicking" a caret in my life ;)
     
    samochreno likes this.
  8. ambid17

    ambid17

    Joined:
    Jun 28, 2017
    Posts:
    7
    Did this ever get addressed? I am currently running into this issue myself. I want to be able to click on an object that contains a TMP_InputField, but the inputfield blocks clicking on the object due to the Caret
     
    samochreno likes this.
  9. matt_trinidad

    matt_trinidad

    Joined:
    Oct 27, 2020
    Posts:
    3
    Yeah, I don't think this ever got addressed. Running into the same issue on TMP 3.0.6, Unity 2021.1.17f1. I
    GetComponentInChildren<TMP_SelectionCaret>().raycastTarget = false;
    on Start of my components as @Stephan_B suggested.
     
    korbul and samochreno like this.
  10. OwenSquirrel

    OwenSquirrel

    Joined:
    Oct 10, 2021
    Posts:
    10
    Any updates if it is possible to set the SelectionCaret component raycast target to false by default without having to use
    GetComponentInChildren
    ? I'd like to avoid using it due to performance reasons
     
  11. earsay

    earsay

    Joined:
    Dec 23, 2017
    Posts:
    4
    Mine too. This should be available on the InputField as a setting or disabled by default.