Search Unity

TextMeshProUGUI class reference not working anymore

Discussion in 'UGUI & TextMesh Pro' started by Abrakidabra, Jul 21, 2018.

  1. Abrakidabra

    Abrakidabra

    Joined:
    May 12, 2017
    Posts:
    62
    Hey, I just updated from 2017 to 2018.2 and now my scripts with the TextMeshProUGUI have gone red, eg

    Code (CSharp):
    1. using UnityEngine;
    2. using TMPro;
    3.  
    4. public class FollowUI : MonoBehaviour {
    5.  
    6.  
    7.     public TextMeshProUGUI speedText; //ref to the speed text
    8.     public TextMeshProUGUI gearText; //ref to the gear text
    It was working fine before the update, and now I dont know what to write to get that class to edit the TMP text from the script. Deleted and imported new TMP folder already, and reopened unity, still the same error...

    PS im a beginner so probably missed something basic.

    Thanks if you can help.
     
    Last edited: Jul 21, 2018
  2. Abrakidabra

    Abrakidabra

    Joined:
    May 12, 2017
    Posts:
    62
  3. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    The TextMesh Pro UPM package is now included by default with Unity 2018.2. As such, if your project still contains the previous version of TextMesh Pro, you should be getting several errors in the console which can lead to the behavior you are reporting.

    If you haven't already done so, you will need to remove the older version of TextMesh Pro from your project by deleting the "TextMesh Pro" folder. Be sure to backup your project first as well as any files or assets you may have saved inside the TextMesh Pro folder hierarchy. See the following post with further details. Note that you will need to convert your project to the new format used by the new TextMesh Pro package which is also detailed in this post.

    Since all packages installed via the Unity Package Manager located in the "Window - Package Manager" menu use Assembly Definitions, I strongly recommend you upgrade to the latest version of Visual Studio 2017 if you are using Visual Studio.

    Let me know if after following the information from the referenced post and here, you still have the issues you reported.
     
    Abrakidabra likes this.
  4. Abrakidabra

    Abrakidabra

    Joined:
    May 12, 2017
    Posts:
    62
    As mentioned in my post, I have done these things. Issue persists. I can access the TMPro namespace, but I am limited to only a few options, none of which are TexhMeshProUGUI
     
  5. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    Are you using Assembly Definitions for your scripts? If so you need to add a reference to the Unity.TextMeshPro assembly. The following post contains information about manually editing the .asmdef.

    You are using the latest version of Visual Studio 2017 which is 15.7.5?

    If the issue persists, make sure you have a back up of the project and delete the project solution which are located at the root of the project (which is where the Assets folder is). Then also delete the Library folder.

    Again let me know if the issue persists.
     
    ben-rasooli and Abrakidabra like this.
  6. Abrakidabra

    Abrakidabra

    Joined:
    May 12, 2017
    Posts:
    62
    Im struggling to follow that post, can you tell me what I should be doing? Where do I find .asmdef? What do I change it too?

    Again "using TMPro;" is green and not giving me an error, but there is only a limited selection of classes under it, not the TextMeshProUGUI which is red. Im using MonoDevelop.

    all I can get is TMPro.TMP_DigitValidator, TMPro.TMP_PhoneNumberValidator, and TMP_TextEventHandler
     
    Last edited: Jul 21, 2018
  7. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    When you open the Package Manager UI, what version of TextMesh Pro does it tell you is installed?

    The folder where your script that gives you an error on the <TextMeshProUGUI> type, does it contain a file of type .asmdef?

    Just for testing, if you create a new project 2D and then add the TMP Essential Resources and TMP Examples and Extras which you can import via the "Window - TextMeshPro" menu, do you get any errors in this new project?

    Are you able to create a simple script that includes "using TMPro;" and add some public fields of type <TextMeshProUGUI> ?
     
    Abrakidabra likes this.
  8. Abrakidabra

    Abrakidabra

    Joined:
    May 12, 2017
    Posts:
    62
    Version 1.2.4

    No, just the scripts I have created.

    No errors. But when I view the scripts in the examples it still says, error cs0103: The name "TMP_Text" does not exist in the current context. It says this for all of them. But the script works somehow.
    No, error cs0103: The name "TextMeshProUGUI" does not exist in the current context. Doesnt work.
     
  9. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    Did you try creating a new project to see if you get the same behavior? Just trying to rule out outside factors like other assets or templates which might affect your existing project.
     
    Abrakidabra likes this.
  10. Abrakidabra

    Abrakidabra

    Joined:
    May 12, 2017
    Posts:
    62
    Yeah look i replied with that info on those tests
     
  11. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    I wonder if the issue might be related to MonoDevelop. Just to confirm these errors do not appear in the Unity console but in MonoDevelop. Correct?

    Are you on Windows or OSX?

    If you are on Windows, I would suggest using Visual Studio 2017 to see if you get the same issues.
     
    Abrakidabra likes this.
  12. Abrakidabra

    Abrakidabra

    Joined:
    May 12, 2017
    Posts:
    62
    The error that appears in Unity is "NullReferenceException: Object reference not set to an instance of an object" When trying to reference the TexhMeshProUGUI.
     
  13. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    Assuming you are using something similar to the code you posted initially, you did assign a text object (TextMeshProUGUI) in those public fields via the inspector?
     
    Abrakidabra likes this.
  14. Abrakidabra

    Abrakidabra

    Joined:
    May 12, 2017
    Posts:
    62
    I tried too, It doesnt let me drag and drop. If i use GameObject.Find("X").GetComponent<TextMeshProUGUI>(); it just doesnt work either.
     
    nurhakeemazman likes this.
  15. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    Are you able to run the Examples included with TextMesh Pro?

    In case you have not imported those already, they are located in the "Window - TextMeshPro - Import TMP Examples & Extras" menu.

    Also can you post a screenshot of one of the text object you have in your scene and that you are trying to assign to your script's public TextMeshProUGUI field in the inspector?
     
    Abrakidabra likes this.
  16. Abrakidabra

    Abrakidabra

    Joined:
    May 12, 2017
    Posts:
    62
    Yup it was monodevelop... working fine now with visual studio..... Thanks so much for your patience!
     
  17. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    Glad it is working and thank you for your patience as well.

    Now I can go sleep since it is 4:35 am for me :)
     
  18. JamesArndt

    JamesArndt

    Joined:
    Dec 1, 2009
    Posts:
    2,932
    I'm experiencing this same issue in Unity 2018.2.5f1 with Visual Studio Community 2017 15.5.6. Funny thing is no script compilation errors, and the text objects are assignable in the inspect. It's just that each TextMeshPro reference in Visual Studio has the red underlines on it. Any ideas?
     
  19. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    This is likely an issue with the project solution synchronizer and / or VSTU but regardless something that needs to be addressed.

    Please submit a bug report with the relevant project as this will be most useful in trying to address this. Once you have the case # please provide it here.

    In terms of potential short term remedy, another user reported that changing the External Script Editor in Preferences - External Tools to something else and then back to Visual Studio worked. I don't know if that required restarting Unity but it is worth a shot.
     
    JamesArndt likes this.
  20. larskroll

    larskroll

    Joined:
    Dec 17, 2013
    Posts:
    52
    I am experiencing the same issue. VStudio can't see the TMPro namespace, but Unity compiles just fine. I have the assembly reference added to my assembly def file. I've tried nuking the solution and project files from the root folder, deleting library and letting Unity reimport everything. No dice.
     
  21. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    As per my post above, switching External Script Editor to something else and back to Visual Studio has worked for some users.

    Updating Visual Studio to the latest release which is now 15.9.8 has also worked for others.

    As per my post above as well, I have not been able to reproduce this on my end and it would be most useful if you could submit a bug report that includes your project so that we can have our scripting guys take a look at this to resolve this issue.
     
  22. larskroll

    larskroll

    Joined:
    Dec 17, 2013
    Posts:
    52
    Done. Case nr
    1138513

    The supporter says they can't reproduce.


     
  23. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    If the support team were not able to reproduce it, I have a feeling this is specific to Visual Studio on your machine. By that I mean something local causes Visual Studio to get confused. This would point to the issue being outside of the Unity project and perhaps in some Visual Studio cache or configuration files.

    Thank you for submitting the report. I'll take a look tomorrow just in case, I have better luck.

    P.S. There has been another update of Visual Studio (I believe since our last exchange) see if updating Visual Studio to version 15.9.9 makes any difference.
     
  24. nurhakeemazman

    nurhakeemazman

    Joined:
    Oct 25, 2018
    Posts:
    1
    This works for me but I added it under Update()
    TextMeshProUGUI scoreText;

    private void Update()
    {
    GameObject.Find("X").GetComponent<TextMeshProUGUI>();
    scoreText.text = ": " + PlayerPrefs.GetInt("Highscore").ToString();
    }

    Hopefully this helps someone!
     
    kamsin25 likes this.
  25. mistergreen2016

    mistergreen2016

    Joined:
    Dec 4, 2016
    Posts:
    226
    The proper type for 2019.x is
    Code (CSharp):
    1. b.GetComponentInChildren<TMPro.TextMeshProUGUI>().text = m.menuName;
    or just TextMeshProUGUI, using TMPro.
     
  26. true_warlock

    true_warlock

    Joined:
    Aug 2, 2019
    Posts:
    60
    I have been having the same issue with 2019.3.4. It cannot be "reproduced" because there isn't anything specifying the issue. The moment you type in at the very top "using TMPro" the TMPro should bring up something to even auto correct its spelling in Visual Studio 2019, but does not. So even if you type something in other lines such as "public TMP_Text text;" or what have you, such should light up (highlight or something) or give a proper spelling for how it is coded, but does not.

    I am currently going to try and install the update to 2019 3.5 and its Visual Studio file. I have completely removed Visual Studio 2017 and 2019 from my computer files (literally everywhere i could find a file), manually removing it from all list files, registry files (which took a very long time even after uninstall), AppData folders, anything where it appeared with Unity itself in those files, and all temp folders. Just in case there was some sort of conflict bug from the older versions and updates. If it still persists I wont be using 2019 at all, remove everything again, and roll all the way back to 2017 where things were at least working and i was getting somewhere.
     
  27. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    Have you tried creating a new project to see if the issue is present there as well?
     
  28. mistergreen2016

    mistergreen2016

    Joined:
    Dec 4, 2016
    Posts:
    226
    try compiling to see if there are errors even if the intellisense isn't working.