- Home /
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;
}
}
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?
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 :/
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
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
Follow this Question
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