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
4
Question by rjth · Apr 11, 2017 at 01:06 PM · uitext

Dynamic textbox with UI

I would like to create a dynamic textbox that is wrapping the text around and adapting to the width and height of the given text. Something like a chat bubble UI. How would you approach this with the Unity UI system?

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

2 Replies

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

Answer by Oliver-Bogdan · Apr 11, 2017 at 01:16 PM

Create an Image (UI/ Image). This will be your background (act as the bubble).

Add a Text (UI/Text) as a child to the image you just created.

On the image add the following components:

  • Vertical Layout Group

  • Content Size Fitter

On the Vertical Layout Group component make sure Control Child Size And Child Force Expand are all selected (for both width and height)

On the Content Size Fitter choose Preferred Size for both Horizontal Fit and Vertical Fit

The background should now resize to adapt to the text.

Comment
Add comment · Show 5 · 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 rjth · Apr 11, 2017 at 01:21 PM 1
Share

Thank you! Just figured it out myself as well (comment below) :) $$anonymous$$arked yours as accepted!

avatar image Oliver-Bogdan rjth · Apr 11, 2017 at 01:23 PM 0
Share

Congrats. I am glad you also figured it out by yourself :)

avatar image Arshak_A · Jun 24, 2018 at 12:16 AM 0
Share

If you imagine a whatsapp type bubble, they often have a max width/horizontal limit. I cant seem to make that work. Do you have any tips?

avatar image RaphaelQuem Arshak_A · Jul 14, 2018 at 11:10 PM 0
Share

$$anonymous$$aybe trying another object with another vertical layout group without the control child size?

avatar image RaphaelQuem · Jul 14, 2018 at 11:24 PM 0
Share

Well, how should the image parent canvas be configured? i tried this solution but as soon as i choose preferred size on the content size fitter the image turns giant

avatar image
2

Answer by rjth · Apr 11, 2017 at 01:20 PM

Okay, figured it out myself.

You will need a parent GameObject (for example an Image) with a Content Size Fitter and a Horizontal Layout Group component. Inside the parent you will add the GameObject with the Text component. On the parent set the Content Size Fitter "Horizontal" and "Vertical fit" to "Preferred Size". On the Horizontal Layout Group set the "Control Child Size" for "Width" and "Height" to true. With the Layout Group you can also add padding to your dynamic text.

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

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

How to supersample TTF text of UI in 3D graphics scene? 0 Answers

How to apply effects to UI Text in Unity 4.6 1 Answer

How do i position this text to go where i want? 1 Answer

Huge Text Problem 1 Answer

Is it possible to make a text with different font families? 3 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