Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by skrilmps · Apr 07, 2017 at 03:00 PM · textmeshcoordinatescoordinate-system

TextMesh Pro characterInfo coordinates

I am having a hard time making sense of the coordinates I get from the characterInfo struct.

I'm using Unity 5.6

I have a TextMeshProUGUI object that is in Paging mode. When it gets to the end (last page) of text, I want to dynamically create a button underneath the last line of text.

To do this, I am getting the coordinates of the last character of text (I've also tried getting the baseline of the last line) and moving down on the y-axis a bit and justifying it to the left.

When I get the coords of the last character I do it like this: Vector3 bottomLeft = mesh.textInfo.characterInfo [mesh.textInfo.characterCount - 1].bottomLeft;

This gives me a result of (56.2, -35.3, 0.0). (My Canvas is 300x300, something I arbitrarily set for now). However, if I manually place an object using the Scene Editor and align it with the last character, Unity tells me its RectTransform coords are (206.8, -63.5, 0).

Why the big discrepancy? What coordinate system does characterInfo use? I've tried converting the result I get from characterInfo using camera.WorldtoScreenPoint, camera.ScreentoWorldPoint, and transform.TransformPoint, but none of these result in coords that I can make sense of either.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
4

Answer by HiddenTess · May 31, 2018 at 09:38 AM

This is an old question, but hopefully, this helps somebody!

You were on the right track with TransformPoint, but you may have called it on the wrong object, or worked with the result in a way that wasn't helpful.

Let's look at your example, above:

 Vector3 bottomLeft = mesh.textInfo.characterInfo [mesh.textInfo.characterCount - 1].bottomLeft;

I'll assume that mesh is your TextMeshProUGUI object, in this case.

You can do this:

 Vector3 worldBottomLeft = mesh.TransformPoint(bottomLeft);

...and this will convert your coordinates of interest into world space. Now this number is going to look very strange to you, because your canvas probably has a scaler on it, so the coordinate space you're used to is not going to correspond with this. If you want to see what this looks like in your canvas space, divide the resulting coordinates by the scale of your canvas.

ANYWAY, once we have those world coords, we should be in business!

Say you want to offset a button called button 50 from the left, and 40 down from your text baseline, something like this should (hypothetically) work:

 Vector3 buttonSpacePos = button.transform.parent.InverseTransformPoint(worldBottomLeft);
 button.transform.localPosition = new Vector3(50, buttonSpacePos.y - 40, 0);

What we're doing here is transforming the coordinates into the button's parent's space, and then using them to position the button. You could have, alternatively, used the world coordinates without modification, and set button.transform.position, instead, but this would make it harder to figure out your offsets.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image TurboHermit · Jun 11, 2019 at 09:51 AM 0
Share

Just wanted to let you know this is exactly what I needed, thanks!

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Can I transform all of my objects by referencing 2 points? 0 Answers

Convert Leap Motion coordinate 0 Answers

Unity 2d position of squares in different units than size. 0 Answers

Problem with rotation order of euler angles when importing MoCap data 1 Answer

Trouble with positions of vertices 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges