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
2
Question by rustofelees · Sep 28, 2015 at 06:38 AM · uitextrecttransform

Content size fitter does not update rect transform immediately

Hello,

I'm trying to update a text component multiple times in a single frame within a coroutine so that it will update it's associated RectTransform. However, I can get the rect transform to update if my code contains a yield return null statement.

Here is my process for a single frame:

  1. Start the coroutine

  2. Instantiate a new object which has horizontal layout, content fitter, text, and recttransform components.

  3. In a for loop, I update/increase the text value of the text component in order to increase the width of the associated rect transform.

  4. After each iteration of the loop I check the sizeDelta.x of the rect transform to see how much the overall width of the rect transform has changed.

  5. End coroutine

At every iteration in the for loop, I check the width of the of the rect transform, hoping that it will have a larger width value (which it should because of the aforementioned horizontal layout and content fitter components). However, after each iteration, i read the rect transforms width value, and it's always the same - the starting value at which it was instantiated.

I can get the rect transforms width to update if I include a yield return null at the end of the loop, but I would prefer to not have to do this as it means that I have to wait frames in order to continually update the rect transforms width.

Am I overlooking something? Is it possible to update a rect transforms width multiple times in a single frame?

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

1 Reply

· Add your reply
  • Sort: 
avatar image
2

Answer by seppukitty · Jan 07, 2016 at 03:36 PM

Hey, probably too late to help you, but perhaps someone else will read this.

I had a similar problem before and ended up using something like this:

   // write title one letter at a time
   foreach (char c in textString) {  
     textComponent.text += c;
     yield return new WaitForSeconds (writeTextDelay);
   }
   
   // Wait for text to size itself
   // Then update the size of the passage so the next passage will go under it
   yield return new WaitForEndOfFrame ();
   _currentPageHeight += title.GetComponent <RectTransform> ().rect.height;

Basically, by using WaitForEndOfFrame you can wait for LateUpdate (where all the rects get resized) and get the rect size in the same frame. You still can't do this multiple times in one frame though. :/ Oh well. That may solve your problem, it did mine.

You can check out more info here: http://www.samuraifight.com/2015/11/15/unity-coroutines/

Comment
Add comment · Show 1 · 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 vampir26 · Nov 05, 2016 at 02:18 PM 0
Share

Hello! I found for me a better solution than using coroutines. I use the content size fitter to set the tooltip box at correct height.

 public Text tooltip;
 public CanvasGroup canvas;
 bool show = false;
 
 void Update()
 {
    if(show && canvas.alpha < 1)
    {
       //use content size fitter here
       canvas.alpha = $$anonymous$$athf.$$anonymous$$oveTowards(canvas.alpha, 1.0F, 5*Time.deltaTime);
    }
 }
 
 public void ShowTooltip(string text)
 {
    tooptip.text = text;
    show = true;
 }

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

36 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

Related Questions

Problem scale ui custom font text 0 Answers

Snap UI Text inside canvas 1 Answer

Get position of specific letter in UI Text 4 Answers

Force Unity UI element to refresh/update? 4 Answers

,InputField backspace returns already send text 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