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:
    11
    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

    Joined:
    Feb 26, 2017
    Posts:
    6,596
    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.
     
    Ghosthowl and HikmetDuran like this.
  3. HikmetDuran

    HikmetDuran

    Joined:
    May 7, 2017
    Posts:
    11
    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:
    353
    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:
    353
    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:
    21
    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!
     
  7. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,596
    Just had a report on this issue tonight which prompted me to do a forum search where I uncovered this thread which I failed to ultimately follow up on. Sorry!

    I will be taking a look at this tomorrow to make sure we get the correct behavior by default and also when set via code.

    P.S. Never hesitate to bump a thread if I fail to provide a reply in a timely manner. Depending on the volume of posts on any given day, it is too easy for me to overlook posts which I really hate and feel bad about. So please feel free to remind me. Also never hesitate to submit a bug report as those also get to me.
     
    Gwom likes this.
  8. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,596
    Actually is there a use case for the sub mesh objects to not be using the same settings as the parent text object?
     
  9. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,596
    The following change will ensure the RaycastTarget property of sub mesh objects will remain in sync with the parent text object.

    upload_2020-4-23_16-34-46.png

    This change will prevent using different settings on the parent and child sub mesh objects. As per my previous post, is there a use case for that?
     
  10. Gwom

    Gwom

    Joined:
    Aug 5, 2015
    Posts:
    21
    Hi @Stephan_B

    Thanks for following up and hope you are well during these crazy times!

    We personally won't change the code as we add TMP through Package Manager and therefore don't have access to the code in our Repo, we don't want to pull it in, as we like to keep it updated though Package Manager so would be great to add this fix into the next Package Manager version.

    I cant think of a use case to have them different (sub mesh and text) and if someone wants this for some reason, i think this is the exception and something they can sort with multiple TMP meshes with and without the block raycast turned on. I see the concern though (you change this, and someone may be relying on this odd behavior) but for me, i think you are more likely to fix a bunch of bugs people didn't know about, we only really found it due to a specifically small button getting covered by a dynamic TMP sprite set at runtime which seemed to oddly not press every time.

    Hope there is not too much fallout if you do push the fix and thanks again for your help
     
  11. Grivas_Publications

    Grivas_Publications

    Joined:
    Aug 26, 2020
    Posts:
    7
    Dear Stephan, I am facing the same problem when turning off a canvas and turning it on again the TMP mesh blocks raycast even though the parent TMP is set not to. I am running TMP 2.0.1 with unity 2019.4.4f1.
    I opened TMPro_UGUI_Private.cs but could not find the code above so i could add the additional line.
    Any help?
    I also thing submeshes should follow the parent option by default.
     
  12. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,596
    Please test with the latest release of the TMP package which is version 2.1.6 for Unity 2019.4. I believe this behavior might have been corrected in subsequent releases as version 2.0.1 is pretty old now.
     
  13. Grivas_Publications

    Grivas_Publications

    Joined:
    Aug 26, 2020
    Posts:
    7
    Thank you! We are weeks from our first product release, so I will leave it for now, but for the next product I will definitely update. Thanks and great work by the way!