Search Unity

TextMesh Pro Textmeshprougui With Sprite, Disabling Raycast Target?

Discussion in 'Unity UI (uGUI) & TextMesh Pro' started by HikmetDuran, Apr 11, 2019.

  1. HikmetDuran

    HikmetDuran

    Joined:
    May 7, 2017
    Posts:
    6
    I use coin icons on my buy buttons.
    Capture.PNG

    So the problem is, when i add the sprite with TextMeshProUGUI, i can disable "Raycast target" option for amount text, but since the coin icon is a submesh, i cannot disable raycast target option for it.

    This is causing failed click when user touches just on the coin...
    Please help, i really need a workaround at least for now
     
  2. Stephan_B

    Stephan_B

    Unity Technologies

    Joined:
    Feb 26, 2017
    Posts:
    3,175
    Disabling Raycast target on the text object in the Extra Settings should disable it on the submesh as well when doing so in the Inspector.

    I just tested this in version 1.4.0 of TMP and it is working as expected.
     
    HikmetDuran likes this.
  3. HikmetDuran

    HikmetDuran

    Joined:
    May 7, 2017
    Posts:
    6
    OH sorry i was so panicked and looking for a separate toggle for it :)
    Thank you so much
     
  4. x4000

    x4000

    Joined:
    Mar 17, 2010
    Posts:
    298
    Using an embedded secondary font, which causes a submesh, is not respecting the raycast target settings of the parent as of 2.01/1.4.1. I'll investigate further and see what I can find out, but it's definitely not working in a bunch of cases for me.
     
  5. x4000

    x4000

    Joined:
    Mar 17, 2010
    Posts:
    298
    Note to anyone else looking for this:

    https://docs.unity3d.com/2019.1/Documentation/ScriptReference/UI.Graphic-raycastTarget.html

    The answer is in the fact that TMP_SubMeshUI inherits from MaskableGraphic.

    If you want NONE of your submeshes to ever react to mouse input (as was the case in my case), then you can simply say:

    subMesh.raycastTarget = false;

    right after:

    TMP_SubMeshUI subMesh = go.AddComponent<TMP_SubMeshUI>();

    inside:

    public static TMP_SubMeshUI AddSubTextObject(TextMeshProUGUI textComponent, MaterialReference materialReference)

    That gets the job done, anyhow.