Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 Kerihobo · Feb 22, 2015 at 06:54 AM · uiguirecttransform

4.6.1 GUI. Get Pos Y property from script?

I am doing some black magic that can hopefully make use of the Pos Y property on uGUI elements.

I'd be SO happy if I could just return the correct value for this, but whenever I try, it doesn't work.

I am using a WorldSpace canvas.

I have tried to Debug.Log() the following:

  • recTransform.rect.position.y

  • rectTransform.anchoredPosition.y

  • rectTransform.position.y

  • rectTransform.anchoredPosition3D.y

it always returns zero like in the following example, except for anchoredPosition.y, which returns 2.0 for some reason.... wtf... what it SHOULD return is -10 :/

I hope using VerticalLayout component hasn't LOCKED my values to zero without telling me or something....

alt text

capture.png (83.1 kB)
Comment
Add comment · Show 4
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 fafase · Feb 22, 2015 at 08:26 AM 1
Share

Have you tried sizeDelta?

avatar image lordlycastle · Feb 22, 2015 at 08:29 AM 0
Share

Try rectTransform.anchoredPosition3D.

avatar image fafase · Feb 22, 2015 at 08:39 AM 1
Share

But it seems you have a layout group on the parent object, not sure you can get anything out of that.

avatar image Kerihobo · Feb 22, 2015 at 10:53 AM 0
Share

@lordlyCastle

tried that too, still a no-go.

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Kerihobo · Feb 22, 2015 at 10:52 AM

fafase, you got it.

So I suppose I should have guessed, but it wasn't entirely obvious to me at first, indeed it seems that LayoutGroup components override the properties of RectTransform in order to get that spacing, scale and position for the grid. This only makes sense.

So what is the problem? Well, if you want to access your RectTransform while the parent has a LayoutGroup component, forget it.

Solution?

I found out that enabling the LayoutGroup ONCE, and then disabling it immediately after, allowed my children to retain their newly acquired transforms that they received from parent's LayoutGroup component. So... if you want nice organized grid, but you want to control the Rect Transforms too sometimes, maybe for animation at certain events... thennnnn...

  • Enable LayoutGroup component on parent.

  • Disable LayoutGroup componenent on parent.

  • job done, you have nicely aligned child GUI elements now, and you can access their posY property or any of their others.

Note: I did however need to apply a LayoutElement component to each of the children to set limits for their min height/width. (To counter the devastating effects of parent's LayoutGroup component).

For Interest's sake...

"Why do you want to do this anyway???":

For special FX, really magical ones that change based on properties of child GUI elements.

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

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

21 People are following this question.

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

Related Questions

Place UI element on pointer up position. 1 Answer

Good way to scale 3D GameObjects in a Canvas (Screen Space - Camera)? 1 Answer

Move UI object to center of screen while maintaining its parenting 2 Answers

RectTransform Pivot Point in the new UI? 1 Answer

Anchor ui image to ui text 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