TMP_Text error in VSCode

I can import TMPro to my ScoreBoard.cs file, however, when I try and create an attribute ‘scoreText’ of type TMP_Text, I get an error. Tried searching online for the solution but nothing. I thought it was something to do with the .csproj files for my Unity project but it isn’t. It’s as if the TMP_Text class doesn’t exist within the TMPro namespace.

Below is my code for the ScoreBoard.cs file:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;

public class ScoreBoard : MonoBehaviour
{
    int score;
    TMP_Text scoreText;

    private void Start() {
        scoreText = GetComponent<TMP_Text>();
        scoreText.text = "Start";
    }

    public void IncreaseScore(int amountToIncrease) {
        score += amountToIncrease;
        Debug.Log($"Score is now: {score}");
    }
}

EDIT: I have tested the game and it works as intended, I just can seem to get rid of the highlighted error with VSCode

Hi,

Welcome to our community! :slight_smile:

Does VS Code also underline TMPro in your code? If not, you could try to change TMP_Text to TextMeshProUGUI.

If the issue persists, go to Edit > Preferences > External Tools (in Unity) and click on the “Regenerate project files” button. That often fixes issues.

Did this help?


See also:

Anything todo with TMPro is underlined. I have sinced progressed onto Realm Rush but the same error persists but a new problem has arose. Becuase the CoordinateLabeler.cs script runs even in editor, Unity won’t run the script unless all of the errors are gone. And because VSCode doesn’t recognise TMPro, I can’t get the script to run.
I have:

  • Closed VSCode and Unity, deleted the .sln and .csproj files, opened unity and regenerated them but to no avail
  • Uninstalled and reinstalled TextMeshPro from the Package Manager then regenerated the .sln and .csproj files.
  • Installed Visual Studio Community to see if TextMeshPro would work with that IDE but nope. Even tried regenerating the .sln and .csproj files for the Visual Studio Community IDE.
  • Created Assembly Definition files references TextMeshPro.
    None of these has worked

Now, I am running:
Unity 2021.2.7f1
VSCode 1.63.2
TextMeshPro 3.0.6

I have the Unity.TextMeshPro.csproj and Unity.TextMeshPro.Editor.csproj files within my projects directory.

Unity 2021.2 seems to have lots of issues. Have you already tested your project with Unity 2021.1?

Before you import your project into another version of Unity, make a backup of your project folder by duplicating it. Save the duplicated folder somewhere else, maybe on an USB stick. To save some free space, you could delete the Library and Temp folders in the backup folder. Import the project, not the backup.

Downloaded Unity 2021.1 and created a new project. Still no luck on both Visual Studio Community and VSCode

Did you follow this instruction?

If so, close Unity and VS. Then go to your project folder and delete the *.sln and *.csproj files. Launch Unity, double click on your script inside Unity and have Unity open VS.

Yes, I followed those instructions.

UPDATE: I am currently using the latest VSCode version and Unity 2020.3.27f1. Intellisense on VSCode still will not recognize TMPro however, Unity will now run the script without any error!

Thank you for your help and I apologize for the inconvenience!

That sounds good. If the script is running, the problem is very likely VS Code, not something you did in Unity.

Are there any messages in the console in VS Code? Maybe one that mentions a missing .NET Framework 4.7.1?

Privacy & Terms