Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
11 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 /
This post has been wikified, any user with enough reputation can edit it.
avatar image
1
Question by rahulkk · Jul 22, 2015 at 09:09 PM · transformrecttransformpointscreenspacelocalspace

Convert local point in RectTransform to screen space

I need to convert a point in a RectTransform to screen space. Basically, I need to do the opposite of what RectTransformUtility.ScreenPointToLocalPointInRectangle does. I have looked at Transform.TransformPoint, except that I need points converted to screen space, not world space.

As an example, the point (0.5, 0.5) in the local space of a RectTransform should get converted to the screen space coordinates of the center of the RectTransform.

How can I accomplish this?

Comment
Add comment · Show 1
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 AltIvan · Aug 08, 2016 at 08:09 AM 0
Share

It is probably something like this:

 Vector2 pos = rect.position + new Vector2 (0.5, 0.5);
 Camera.main.WorldToScreenPoint (pos);

2 Replies

· Add your reply
  • Sort: 
avatar image
3

Answer by Tomer-Barkan · Apr 19, 2016 at 03:59 PM

use GetWorldCorners() or Transform.TransformPoint() and then use RectTransformUtility.WorldToScreenPoint().

     Vector3[] corners = new Vector3[4];
     rect.GetWorldCorners(corners);

     Debug.Log("Screen point1: " + new Vector3(rect.rect.xMax, rect.rect.yMin, 0) + rect.position);
     foreach (Vector3 corner in corners) {
         Debug.Log("World point: " + corner);
         Debug.Log("Screen point: " + RectTransformUtility.WorldToScreenPoint(null, corner));
         Debug.Log("Viewport: " + Camera.main.ScreenToViewportPoint(corner));
     }
Comment
Add comment · 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
1

Answer by nisovin · Jul 22, 2015 at 09:54 PM

You should be able to use Transform.TransformPoint to convert from local space to world space, then use Camera.WorldToScreenPoint to convert to the screen point of the given camera.

Comment
Add comment · Show 3 · 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 rahulkk · Jul 23, 2015 at 04:35 PM 0
Share

Could you provide a code snippet please? I have tried doing something like this before, but it didn't seem to work.

avatar image Tomer-Barkan · Apr 19, 2016 at 02:41 PM 0
Share

It doesn't work. the world coordinates it returns is relative to the canvas not the camera, so the second transformation will return a really large number.

I'm still trying to figure this one out myself.

avatar image Juskiesskalt Tomer-Barkan · May 31 at 10:28 AM 0
Share

I got it by just using RectTransform.TransformPoint. Correct me if I'm wrong but I believe this converts to screen space. At least in my testing this worked fine.

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

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Convert RectTransform rect to screen space 12 Answers

How to transform points from world to camera space and back again. 1 Answer

How to place the GameObjects in a sequence on the plane 1 Answer

Simple Transform question, using Quaternion.LookRotation 0 Answers

How to covert a rectTransform scale to world scale? 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