Search Unity

TextMesh Pro Textmeshprougui With Sprite, Disabling Raycast Target?

Discussion in '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,960
    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:
    313
    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:
    313
    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.
     
  6. Gwom

    Gwom

    Joined:
    Aug 5, 2015
    Posts:
    12
    We tried @x4000 's fix, but it is not ideal for us as we would have to import the Package into the build as we use Package Manager for TMP and therefore changing the subMesh.raycastTarget = false; in the file:
    Library\PackageCache\com.unity.textmeshpro@2.0.1\Scripts\Runtime\TMP_SubMeshUI.cs would be outside of source control (library folder), and didn't want to move it outside of the Package Manager framework as pointed out in the thread here.

    Upon investigation though, I don't believe this was our issue although we were getting blocked raycasts. I think this original version of the issue maybe fixed in the version of TMP we have (2.0.1), but we did find an issue when we set the text in code, it again forgets the ray cast setting / does not use the TMP_Text raycast setting. To reproduce, you can make a TMP_Text field with Raycast Target set to false, then in code, set the text to something needing a sub mesh e.g. <sprite="Sprites" name="Name"> and you will find it blocks raycasts until the Raycast Target is toggled off and back on again in the editor.

    We could do a hack for this but would be great if this could be fixed. @Stephan_B can you recreate this issue? Would be great to get a fix!
     
unityunity