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 PsychoDuckArcade · Nov 21, 2014 at 11:04 AM · uiguitransformrecttransformelement

Setting values of a Transform childed to a RectTransform giving unexpected results.

Straight forward code, straight forward problem:

 itemGraphics[itemSlot.IndexInList] = (GameObject)Instantiate(itemSlot.Item.ModelAsset);
         itemGraphics[itemSlot.IndexInList].transform.parent = itemSlot.transform;
         itemGraphics[itemSlot.IndexInList].transform.lossyScale.Set(1, 1, 1);
         itemGraphics[itemSlot.IndexInList].transform.rotation = Quaternion.identity;

It's giving unexpected values in the inspector for scale and rotation. The parent (itemSlot) of the child (itemGraphic) is a worldspace ui element, so it has a RectTransform, where as the child itemGraphic is a regular gameobject with a regular Transform.

I tried editing local scale and local rotation instead; same issue. I tried parenting after setting scale and rotation (tried both local and world) and still same issue.

All I want to do is child a 3D graphic to a 2D UI element.

EDIT: Sceenshots of the output:

alt text

After changing scale to 1 and rotation to 0 through inspector at runtime:

alt text

EDIT: I just figured something out. It seems to be scaling down the child's x and y by the parent rectTransform's width and height. The rectTransforms width and height is 50, so if I scale the child's x and y to 50, it returns to normal.

I guess if there's no better way, I can just code it to scale up the child by the parents width and height...

EDIT: ^Actually that still doesn't work. For some reason the final scale is some crazy high numbers in the thousands. Something's retransforming it after I do.

Also if I change the values at runtime in the inspector, if the rotation isn't 0,0,0, the model skews even though the scale doesn't change.

This is all very strange behaviour, I wish I could fine documentation on how rectTransforms and transforms are supposed to work together.

untitled.jpg (457.7 kB)
untitled2.jpg (415.0 kB)
Comment
Add comment · Show 2
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 koray1396 · Nov 21, 2014 at 11:09 AM 0
Share

I haven't tried this, but can you try to set the position of child object with worldtoviewportpoint?

avatar image PsychoDuckArcade · Nov 21, 2014 at 10:53 PM 0
Share

The position actually seems fine. Just the rotation and scale get all messed up. It's all stretched and skewed.

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by Bunny83 · Nov 21, 2014 at 11:09 PM

You can't set the lossy scale. It's readonly and all you do is reading the lossyscale and then you change the returned value. Vector3 is a value type. lossyScale is a property which doesn't have a setter, only a getter. The lossy scale is approximated from the transform hierarchy but depending on the rotation / translation / scale of the parents.

Setting the localScale before parenting should work as Unity adapts the scale to try to maintain the current scale. Once parented the scale might be changed depending on the scale / rotation / translation of the parents.

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 PsychoDuckArcade · Nov 22, 2014 at 12:16 AM 0
Share

I tried that:

 itemGraphics[itemSlot.IndexInList] = (GameObject)Instantiate(itemSlot.Item.$$anonymous$$odelAsset);
         itemGraphics[itemSlot.IndexInList].transform.localScale = Vector3.one;
         itemGraphics[itemSlot.IndexInList].transform.rotation = Quaternion.identity;
         itemGraphics[itemSlot.IndexInList].transform.parent = itemSlot.transform;

Same issue still.

avatar image Bunny83 · Nov 22, 2014 at 05:41 AM 0
Share

Well, that probably means that your hierarchy has some strange scaling on the z axis. I don't really use 4.6 so i hadn't much time to look through the new features. It might be possible that a rect transform (which is ment for 2d gui) might set some strange z scale (0 for example). Is it that important to have the 3D object as child of the 2D button?

avatar image PsychoDuckArcade · Nov 22, 2014 at 08:16 AM 0
Share

In the inspector it shows the z scale as 1 for everything. And if I`m not supposed to child 3D objects to 2D UI elements, how else am I supposed to attach 3D meshes to my GUI? Only way I can think of would be to not child them to anything and hardcode transform values in Update();

I thought one of the features of the 4.6 UI was that rectTransforms were compatible with regular Transforms, but it doesn't seem to be as simple as that and I can't find any documentation, examples, or tutorials on how it's supposed to be done.

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

28 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 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

4.6.1 GUI. Get Pos Y property from script? 1 Answer

SetAsLastSibling seems to sort alphabetically when used across different objects. 0 Answers

Get position of specific letter in UI Text 4 Answers

RectTransform Pivot Point in the new UI? 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