Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 11 Next capture
2021 2022 2023
1 capture
11 Jun 22 - 11 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
1
Question by Hivemaster · Aug 05, 2015 at 12:53 PM · uicanvasrecttransform

Problem copying RectTransform UI elements

Hi all,

I'm having an issue where, more often than not, if I try to copy a child element of a UI gameObject (i.e. something with a RectTransform and CanvasRenderer), it gets created, but isn't visible. Instead, Unity displays a grey transparent disc where it should be.

In the Editor, copy-pasting the values from the previous object's RectTransform component into the new copied RectTransform fixes the issue - but no value appears to have changed.

Worse, in code, I can Instantiate() copies, but the same issue happens, and I know of no way to 'fix' the RectTransform in this case. This happens both with copying an existing element in the hierarchy, and with Instantiating it from a prefab.

Is it entering some kind of disabled / invalid / un-renderable state? If so, what's the cause, and why does refreshing the (apparently) same values on a RectTransform fix it?

Thanks!

Comment
Add comment · Show 3
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 troien · Aug 05, 2015 at 02:38 PM 1
Share

After you instantiate them, do you change the parent? (Using transform.SetParent). If so, this method has also a second argument called worldpositionstays. Setting this to false can fix some of these issues.

Also, not calling SetParent at all after Instantiating might yield the same problems. Not 100% sure though.

If this is the case, then the problem is that the thing you try to copy is a child of another RectTransform. When you then instantiate it, it gets instantiated with a different parent (no parent). And thus the resulting world position is wrong. (world position and size get calculated out of the values in the RectTransfom's inspector and that of it's parents)

If you then set the parent and keep the world position and size the resulting world position and size will still be wrong.

If you ins$$anonymous$$d set the parent while not keeping the world position, the new worldposition and size that is calculated should be equal to the item you copied (Given they have the same parent)

avatar image gorsefan · Apr 18, 2016 at 11:20 AM 0
Share

I think I am seeing the same problem -- click anywhere in the hierarchy, create a new UI element like Image or Panel, Unity inserts the item in a see$$anonymous$$gly random place in the hierarchy. So naturally one wants to move it to the correct place i.e. inadvertently change transform parent, which breaks the Rect Transfom (the little anchors graphic where you set the anchors is just greyed-out) and the item no longer renders

avatar image troien gorsefan · Apr 18, 2016 at 01:17 PM 0
Share

If you can replicate the problem, you might perhaps want to report it as a bug if you think it is a bug. I think it might be something else, but given the limited information you have, all I can do is guess :p


Do you mean that the item's anchors and width/height/etc. are greyed out in the inspector? If so, it means something else is setting it. For instance a Layout group on its parent or a contentsizefitter on itself (because you say it happens when you change parent, it's most likely a layoutgroup on the new parent).

If that is the case, you can add a LayoutElement to your element and make sure the calculated width/height value is higher then 0 ;)

Another aption would be to add a LayoutGroup to your element for the same reason (In case you want child(s) of your element to control its preferred width/height).

And yet another option could be to change the properties of the parent LayoutGroup (checking the child force expand bools for instance)


Also, when rightclicking in the hierarchy, followed by UI-->[something] in the context menu ins$$anonymous$$d of UI-->[something] from the GameObject menu in the top. The new Image/Panel/etc. will be placed as a child of the object you right clicked (only if the object you clicked has a canvas somewhere up in his hierarchy).

0 Replies

· Add your reply
  • Sort: 

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

Move a UI element with respect to canvas scaler 0 Answers

[SOLUTION] set UI RectTransform Anchor Presets from code c# 1 Answer

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

Find UI Image position in Screen Space 1 Answer

Editing RectTransform scale 2 Answers


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