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 D3Duck · Jun 09, 2018 at 10:20 PM · uiinputfield

Auto layout and content fitter with InputField

I've been making a UI which is very dynamic. Part of it is that I have a vertical layout group containing multiple InputField objects and these need to fit whatever content is put in by the user.

The Width is not variable and I need the input field to grow vertically based on the value string.

With a text field it works and I can insert any length string and the rect will grow downwards and make everything fit. Yet with an input field this does not really seem to be supported the same way.

After looking at it, it seems that the input field makes the text object just contain what is visible and the rest 'scrolls', so is not actually part of the Text.text. So therefore my content fitter and vertical layout group only cause a preferred height of about 21, showing one line (input field is set to multi-line) as this is all that is really in the text field.

I really don't want to have to figure out how to write my own input field but could not find anyone else with the same problem. Is there a known solution for this? The simplicity is that I need to text child of the input field to not 'scroll' but contain all text at all times so my auto layout works.

Edit: yes it is wrapped. Also tried to not wrap it with no luck.

I noted that disabling and reenabling the LayoutElement resulted in it fixing. I just fixed the problem by adding this script onto the same GO as the inputfield:

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.UI;
 
 /// <summary>
 /// This is to update the element as otherwise the Inputfield will not update correctly and show the whole text. Instead, inbuilt functionality will 'scroll' the text (cut parts that 'dont fit' into the text field) and not resize the text.
 /// </summary>
 public class InputFieldHack : MonoBehaviour
 {
     LayoutElement element;
 
     void Awake()
     {
         element = GetComponent<LayoutElement>();
 
 #if UNITY_EDITOR
         if(element == null) Debug.LogError("Element == null");
 #endif
 
         GetComponent<InputField>().onValueChanged.AddListener((value) => { HackTheSystem(null); } );
     }
 
     public void HackTheSystem(string value)
     {
         //Hack much?
         element.enabled = false;
         element.enabled = true;
     }
 }

This results in some sort of update that rescales everything correctly. Removing the script results in it breaking again as above.

Unity bug?

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
0

Answer by Wyattagum · Jun 10, 2018 at 06:06 AM

Use vector layout component for an auto layout

Comment
Add comment · Show 4 · 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 D3Duck · Jun 10, 2018 at 06:18 AM 0
Share

You mean LayoutElement? Tried that and does not work as that is not dynamic in this use case - you can only put in a hard value for preferred height, etc. The point is that the text does not display in text.text due to the 'scrolling' of the InputField which is done automatically and cannot be turned off as far as I can see.

avatar image NoDumbQuestion D3Duck · Jun 11, 2018 at 03:08 AM 0
Share

Inputfield is just another UI with script. Try again.

You might not setup layout for Inputfield children correctly.

Also, you need auto-fit(Scale based on parent size) not Layout Element

avatar image Wyattagum · Jun 10, 2018 at 03:59 PM 0
Share

Did you wrap it?

I just woke up so some of my answers are stupid

avatar image D3Duck Wyattagum · Jun 11, 2018 at 02:38 AM 0
Share

I did, see edit

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

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

NullReferenceException after passing InputField gameObject into EventSystem.SetSelectedGameObject() 1 Answer

adding a image inside of a muilti line Input Field? 0 Answers

Problems selecting input field 1 Answer

How to disable character movement while editing InputField? 1 Answer

How to insantiate an Inputfield which is populated with numerical values and to add the values of the field to get an output values? 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