Search Unity

Question Get Oculus VR LaserPointer to recognize raycast intersection to TMPro_Text

Discussion in 'XR Interaction Toolkit and Input' started by TheCircadian, Mar 4, 2021.

  1. TheCircadian

    TheCircadian

    Joined:
    Jul 30, 2016
    Posts:
    16
    I have a TMPro_Text prefab that I use to create a lot of labels in my scene. I want to modify the size of the text when my LaserPointer intersects with the text, but even though the TMPro_Text prefab is on the UI Layer, and the LaserPointer successfully can click on other UI Buttons, it goes straight through the TMPro_Text object, with no ability to recognize hovering or clicks. Same thing happens with regular Text objects.

    I've tried adding an EventTrigger to the GameObject, as well as using TMP_TextUtilities to find the intersecting word, but not having any luck. Is there something I'm missing here?
     
  2. NemesisWarlock

    NemesisWarlock

    Joined:
    Jan 21, 2017
    Posts:
    141
    Is this on a Button(TextMeshPro), or just a straight object with a TextMeshPro - Text (UI) component?

    "Intersect" isn't the word you're looking for, BTW, it's "Raycast Target".
     
  3. TheCircadian

    TheCircadian

    Joined:
    Jul 30, 2016
    Posts:
    16
    The TMP_TextUtilities library uses "Intersect" a lot in their methods (FindIntersectingWord, FindIntersectingCharacter, etc.), and from this video that library in general seemed to capture the functionality I'm looking to recreate, so I was just trying to use their general terminology. You're right though, "Raycast Target" is probably more appropriate for the feature itself in a general Unity functionality context.

    I'm trying to do this with a Text UI component, not a Button. It's easy to do with a Button. Doesn't necessarily have to be TMPro or not, although from what I've seen (like in that video) there is more support for functionality like this for non-Button elements through TMPro. Just a few early attempts in replacing the cursor transform of their 2D demo (`Input.mousePosition`) with the LaserPointer from Oculus' VR system didn't get me anywhere.
     
  4. tylerscottslater

    tylerscottslater

    Joined:
    May 26, 2022
    Posts:
    1
    @TheCircadian , did you ever figure out a solution for this?
     
  5. VRDave_Unity

    VRDave_Unity

    Unity Technologies

    Joined:
    Nov 19, 2021
    Posts:
    275
    Hey @tylerscottslater,
    There are 3 options to get this working:
    1: Use the standard TextMeshPro - Text (
    TextMeshPro
    ) with a transparent image behind it set the checkbox on the Image for Raycast Target.
    2: Use the TextMeshPro - Text (UI) (
    TextMeshProUGUI
    ) which has the Raycast Target checkbox similar to the non-TextMeshPro UGUI Text component.
    3: Add a Tracked Device Physics Raycaster to the scene and then put a MeshCollider on the TextMeshPro - Text object. The only issue here may be performance, as it will do a lot more physics calculations with the Mesh Collider that is fit to the letters of the text.

    Let us know if these work for you!