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 ILoveMyDada · Apr 12, 2018 at 11:44 PM · textstringtextmeshnulldoesnt

TextMeshPro " != " not working

Hi so I am switching from the standard Unity Text format to TextMeshPro. And everything is working fine for the most part. My only problem is that my 'if' statements with " != ", don't work at all. When I run the game and the input field is selected but nothing has been typed, the 'then' statements all run when they shouldn't be. I've tried replacing "" with null and that also does not work. It worked fine with the standard Unity Text but for some reason it wont with TextMeshPro. Any help would be appreciated. Thanks!

.

 void Update()
 {
     if (Input.GetKeyDown(KeyCode.Return) && NameInputFieldTexttext.text != "" ) 
     {
         SceneManager.LoadScene (SceneToLoad);
     }

     if (NameInputFieldTexttext.text != "") 
     {
         PressEnter.GetComponent<FadeOutText> ().enabled = true;
         PressEnter.GetComponent<BlinkingText> ().enabled = true;
         PressEnter.GetComponent<TextMeshProUGUI> ().enabled = true;
     }


 }
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 Bunny83 · Apr 13, 2018 at 12:58 AM

I never used TextMeshPro so i'm not sure what the issue might be. However it's possible that the string actually contains a line feed or carriage return character. Try adding using System.Linq; at the top and add those two lines inside your if statement:

     string s = NameInputFieldTexttext.text;
     Debug.Log("Text: " + s.ToCharArray().Aggregate("", (a, c) => a +" "+ ((byte)c).ToString("X2")) + "("+s.Length+")");

This will print the content of the string as a hex sequence and also shows the length of the string in brackets. Try running that code and show us what gets printed.


Maybe your input field is a multiline input field?

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 ILoveMyDada · Apr 13, 2018 at 01:04 AM 0
Share

Thanks for the reply! This is what I got with the Debug you gave:

Text: 0B(1) UnityEngine.Debug:Log(Object)

What you thinkin?

I also changed the Input Fields Line Type to $$anonymous$$ultiline but that still didn't really do anything :/

avatar image Bunny83 ILoveMyDada · Apr 13, 2018 at 01:35 AM 0
Share

Well, "0x0B" or "11" in decimal is the vertical tabulator character. I have no idea where this might come from as it's a control character that is rarely used today (unlike the "normal" horizontal tab "0x09"). This might be a fragment of how textmesh pro handles text. You could simply filter that character like that:

 if (Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.Return) && NameInputFieldTexttext.text.Replace("\v","") != "" ) 
 {

Though it's probably worth to actually figure out where it comes from. You may want to contact the creator of Text$$anonymous$$eshPro

avatar image ILoveMyDada Bunny83 · Apr 13, 2018 at 01:53 AM 0
Share

Ok I gotcha. I'll try and see if this is something they know is a problem or not. Thanks for the help!

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

81 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

Related Questions

If Statements with PlayerPrefs 1 Answer

Text Mesh Scripting 1 Answer

UI components all disappear on Play mode, then stay invisible 2 Answers

Cannot Import TextMeshPro Essentials 0 Answers

Unity UI: Text Adventure 2 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