Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 awalltoo · Apr 08, 2016 at 04:33 PM · uilayouttween

Tweening a RectTransform between AutoLayouts?

I have two HorizontalLayoutGroups, each with some unknown number of items in them. I want to move an object from one to the other. This seems simple enough:

 theObject.transform.SetParent(otherLayoutGroup);
 // Wait one frame for the other layout group to update it's position

However, what I actually want is to do a nice tween to animate the object moving from its current position on screen to the new position. I can't figure out a good way to do this. As far as I can tell, there is no way for me to figure out what an object's position in the new layout group would be without actually moving it there and waiting for the layout group to update.

 // Save the object's old position
 previousPosition = theObject.GetScreenPosition();

 // Calculate the destination position
 theObject.transform.SetParent(otherLayoutGroup);
 // Wait a frame
 var newPosition = theObject.GetScreenPosition();

 // Move the object to a non-auto-layout layer so nothing
 // screws with its position while I'm trying to tween it.
 theObject.SetParent(someOverlayLayer);

 // Do the tween
 theObject.setScreenPosition(previousPosition);
 theObject.TweenPosition(newPosition);
 // Wait for the tween to finish

 // Add the object to the destination layout group for real this time
 theObject.SetParent(otherLayoutGroup);

There are a still some problems with this approach though. First of all, GetScreenPosition() and SetScreenPosition() don't exist and I'm not entirely sure how I'd implement those. Presumably I'd do so by reading/modifying the object's transform.position, but I'm not sure how that relates to the offsets that I'm used to dealing with for RectTransforms.

Even then, this solution isn't great. First of all, I have to wait a frame for the destination layout group to update before I can start tweening, so the object will appear to warp to its destination for a frame before it begins moving. Also, I can't have the object parented to either of the layouts while it's in transit, meaning that any other objects in either layout group will immediately "snap" as soon as the tween begins or ends and I call SetParent.

Moving an object from one layout group to another seems like a common enough task that there must be a better way to do this that I just haven't figured out yet. Does anybody have any suggestions? Thanks for any help!

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

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

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

Stretching 90° rotated RectTransform to the size of the Canvas 0 Answers

Need some help regarding UI layout in different Screen resolutions 1 Answer

Layout group items are not fitting well 0 Answers

Input field in layout 0 Answers

Grid layout group stretching 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