Search Unity

TextMesh Pro TMP_TextUtilities.FindIntersectingWord() & VR raycast-laserpointer problem

Discussion in 'UGUI & TextMesh Pro' started by pentti3d, Mar 8, 2019.

  1. pentti3d

    pentti3d

    Joined:
    Dec 18, 2018
    Posts:
    7
    Hi, I am trying to use TMP_TextUtilities.FindIntersectingWord(TMP_Text textField, Vector3 raycastHit.point, Camera currentCamera) for selecting distinct words by pointing them with laserpointer using Vive controllers. So, I use raycast to get the Vector3 position which apparently isn't the use case designed for this method.

    This actually works; I can get the right indexes of the words by pointing them ...as long as I have a slave moving the physical mouse to feed input which will not be used but to make this method to fire at all. I tried to add a virtual input module to scene's EventSystem, a virtual cursor on canvas now shows mouse movement in eventsystem window but this is not enough. I still need to touch the mouse to get the index of the word.

    So, is there a way I can get the index of a word just by Vector3 position without moving mouse or hacking the whole event system (which I know little more than nothing about) when using TextMesh Pro text fields?
     
  2. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,596
    Just for testing, load Example 12 and 12a including in the TMP Examples & Extras to see if using the mouse and then your alternative input device if you get the correct behavior in terms of word highlighting.

    If both mouse and pointer works correctly in those examples then your issue is likely the pointer returning vector coordinates that are in an incorrect space. Compare the returned values for the mouse vs your pointer. The Input.mousePosition is in screen space. Your pointer might be returning vector3 values in worldspace or something else.
     
  3. pentti3d

    pentti3d

    Joined:
    Dec 18, 2018
    Posts:
    7
    Actually, the method returns -1 (no word found on Vector3 position) when the mouse is not moving, I just was filtering these so they didn't show in my debug log. Sending the same position to method then returns correct index when mouse is moving, as long as position parameter is on one of the words. I can use hardcoded value too, and then the same happens: Mouse does not move - returns always -1, mouse moves - returns the index of the word in hardcoded position.

    Moving the mouse helps to get the right return values in Scene window. In Game window, all mouse and keyboard actions which affect as inputs makes the same. So, correct behavior of this method seems to be tied to activity on traditional input methods. Because my use case is not using them, I have no idea how to get this working.
     
    Last edited: Mar 8, 2019
  4. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,596
    Does the vector 3 returned by your pointer match the vector 3 position of the mouse? I am talking about the Vector3 value provided to the function.

    In the example 12, the Vector3 for the mouse position is obtained using Input.mousePosition. Is this Vector assuming you are placing the mouse and you pointer on the same word return about the same values (again of the Vector3).

    I am asking to make sure both Vector3 are in the same coordinate space.
     
  5. pentti3d

    pentti3d

    Joined:
    Dec 18, 2018
    Posts:
    7
    I have no mouse position in my scene because I am using world space canvas, as I'm using VR gear and laser pointer to select words. I cannot combine these both pointing methods at the same time because mouse moves in 2d overlay but VR laser pointer hitpoint is in 3d world. Using VR & laser pointer with 2d screen space overlay is just an impossible concept.

    I strongly believe that my pointer coordinates when pointing a specific word are right, as the TMP_TextUtilities.FindIntersectingWord returns the correct index. The problem is that it does return a value other than -1 only while giving "noise input" with mouse or keyboard at the same time when pointing the word or giving the coordinates to the method by some other way. Because the example scene (Screen Space - Overlay Canvas) works correctly also without "noise input", I believe the problem might be that my use case isn't something this is originally designed for; The method basically works when used this way too, but not well enough because without noise input "something is blocking it".
     
  6. pentti3d

    pentti3d

    Joined:
    Dec 18, 2018
    Posts:
    7
    Ok, I just noticed that Vive controller's trigger input also helps the method getting right index. So I am able to create a workaround this way, it is just not possible to get highlighting for words while sweeping the text area with the laser pointer. But most important, selecting words is still possible :)

    It would be very nice if you will have resources to make this more usable in VR somewhere in near future. Getting word indexes quite easily by pointing them with mouse is a cool feature, but getting this done also in VR without problems would be even much more cool. The problem is probably that it has been designed only mouse usage in mind and I just need to use it "wrong way".