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
5
Question by demonpants · Mar 17, 2016 at 09:04 PM · animationuilayout

Is there a way to animate dynamic layout group changes?

I have a reasonably complicated layout system in my UI that allows for anywhere from 1 to 16 elements. These elements are in either 1 or 2 rows, and are dynamically centered and resized based upon how many elements were added.

I do this by adding all the elements into the scene, then setting the game objects active or inactive based upon how many elements I want.

This works great – they are positioned correctly, resized, etc. There's just one problem – any layout group changes happen instantaneously, which is jarring for the user.

Is there any way to make the layout basically lerp its changes, as opposed to instantaneously doing them?

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 jebemti · Mar 17, 2016 at 09:55 PM -1
Share
 float lerp(float v0, float v1, float t) {
   return v0 + t*(v1-v0);
 }
avatar image demonpants jebemti · Mar 20, 2016 at 06:03 PM 0
Share

...really? $$anonymous$$aybe my question wasn't clear. But, your answer... I guess a lot of people don't know how to do much, but I'm not one of them. I have several published games, I am a professional, I know what I'm doing. The question is: when I add another item to a layout programmatically, I don't want everything to snap into its new places, I want it to position slowly. Unity does this position change automatically, there is nothing for me to lerp. I'm basically looking for a checkbox or another technique.

2 Replies

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

Answer by demonpants · Mar 20, 2016 at 06:51 PM

So here's how I did it:

1) Create the hierarchy of what you want in your layout system. Make all those layout elements empty rect transforms (maybe with aspect fitters or layout elements or whatever you need).

2) Duplicate the hierarchy, and put in your visual elements (Image, Text, etc) instead. Delete all layout components from this duped hierarchy (no grids, horizontal layouts, aspect fitters, etc).

3) In every duplicated hierarchy element, I added a script that has it smooth follow its corresponding layout element in the layout hierarchy.

This way, all the player sees is the visual element as it tries to smoothly move to the logical layout position and size.

Comment
Add comment · Show 10 · 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 maxoulaf · Sep 29, 2016 at 10:18 AM 0
Share

That's really useful, thanks !

avatar image elenzil · Nov 11, 2016 at 06:04 PM 0
Share

dang. that's pretty involved.

avatar image demonpants · Nov 11, 2016 at 06:31 PM 0
Share

Yes, it is. It really should be a built-in feature. On the plus side, once you start following this pattern, it's very easy to replicate everywhere.

avatar image demonpants demonpants · Nov 11, 2016 at 06:34 PM 0
Share

At some point in the future, I will likely make an Asset Store bundle for this. I'll also make it handled by a single script, and will automatically dupe the hierarchy etc at run time, ins$$anonymous$$d of having to do all this manually.

avatar image latorril · May 08, 2017 at 10:28 AM 0
Share

I lost my s*** when I looked at this picture and realized it was you. Thanks yo, I'm using this advice right now.

avatar image demonpants latorril · May 08, 2017 at 07:44 PM 0
Share

Haha. Glad this is useful for you. I also have the scripts that do this if you want them.

avatar image ingle · Jun 25, 2018 at 01:53 PM 0
Share

is there a video tutorial? I'm not understand how you did it. :(

avatar image ingle ingle · Jun 25, 2018 at 01:58 PM 0
Share

Are you mean:use the invisible rect to response the control of layout system,and visible element follow it's invisible rect?

avatar image demonpants ingle · Jun 25, 2018 at 06:48 PM 1
Share

Yes, essentially. There are 2 canvas groups that have the same hierarchy. One group has all the layout data in it but no Image component or anything else visual. The other has no layout elements at all, but all the visual elements. It also has some code in it somewhere that causes it to interpolate its position and size to match its corresponding layout element.

Show more comments
avatar image
1

Answer by dhanrajsinh24 · Jul 25, 2017 at 06:46 AM

Hi, I've done it like this: you can use all your group elements as LayoutElements then Instantiate that element as a "dummy element" to know its location in layout and then Instantiate "original element" with "Ignore Layout" on so you can animate it at the position of dummy element, and when the animation is done you can set "Ignore Layout" false again. I hope this makes sense.

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

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

Can't animate UI element whose values are controlled by a layout group 0 Answers

how to extend the GUILayout scrollview's function? 0 Answers

What is the LayoutElement.FlexibleWidth/FlexibleHeight above 1 for? 0 Answers

Can I make animations snap to a frame? 1 Answer

How do I code a custom LayoutGroup? 0 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