• 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 /
  • Help Room /
avatar image
3
Question by bigbosss · Oct 14, 2018 at 02:58 PM · textgame

How to get Text from TextMeshPro input field

 using TMPro;
 
 public class ButtonsScript : MonoBehaviour {
           public TextMeshProUGUI register_username; //drag and drop element
           
           public void getValue(){
                  string username = register_username.text; //here the value is "a"
                  if(username.Equals("a"){  //however here does not find it equal
                          Debug.Log("here");
                  }
           }
 }

I cannot understand why the string username is not equal with "a".even if i enter the string "a" in the input field.Can anyone help me?

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

6 Replies

· Add your reply
  • Sort: 
avatar image
4

Answer by nmill99 · Jul 03, 2020 at 11:33 PM

Here are a few things to make this work in version 2019.4.0f1

  1. using TMPro;

  2. GameObject inputField; // This should be the input parent field and not the child text field. See this post for more details.

  3. string text = inputField.GetComponent<TMP_InputField>().text;

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 nmill99 · Jul 11, 2020 at 07:57 AM 0
Share

Unity Answers changed the URL. I can't control it.

avatar image
2

Answer by OleIvanoff · Mar 10, 2019 at 11:08 AM

A bit old, but still @bigbosss Another forum answer was: https://answers.unity.com/questions/1562568/how-to-get-text-from-textmeshpro-input-field.html

You need to access the text of the TextmeshPro input field from the TMP_InputField class as TMP_InputField.text If you access the text directly from the text component it will not give the result you want.

Comment
Add comment · Show 3 · 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 I2evard · Jun 08, 2020 at 04:05 PM 0
Share

The link you gave return to here

avatar image LoloMiMama · Jul 09, 2020 at 01:12 AM 0
Share

Your link redirects here......................

avatar image StarArcher · Aug 28, 2021 at 10:36 AM 0
Share

To help clarify:

this.GetComponentInChildren<TMP_Text>().text accesses the Placeholder

this.GetComponentInChildren<TMP_InputField>().text accesses the Text

alt text

screen-shot-2021-08-28-at-53457-am.png (12.4 kB)
avatar image
1

Answer by Nick_Laza · Feb 05, 2020 at 04:18 PM

Instead of declaring it with TextMeshProUGUI register_username, use TMP_Text register_username; if you have a Text - Text Mesh Pro in your scene

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
avatar image
1

Answer by SmulDev · May 03 at 01:24 PM

using TMPro;

public TMP_InputField register_username;

string username = register_username.text;

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 dadofsambonzuki · May 16 at 08:01 PM 0
Share

Excellent, thanks. This worked for me after spending hours trying to figure out why I had trailing zero width spaces!

%E2%80%8B

avatar image
0

Answer by OrbitingOrange · Aug 02, 2019 at 12:04 AM

So this doesn't exactly work. What you need to do is grab the TextMeshProUGUI, which I would demonstrate but this apparently hates angle brackets.

There's a much more in depth explanation Here

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
  • 1
  • 2
  • ›

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

198 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image 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

Text Will not disappear after Object Destroyed,Text Wont Go away after object disappears. 1 Answer

Simple Game Over script 2 Answers

Text adventure game, how to change text in a specific way with C# 1 Answer

How do I check mystate for previously being a specicfic state and call a different state if mystate was that state? 1 Answer

Text is Distorted : Android 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