Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Cannot implicitly convert type `TMPro.TextMeshProUGUI' to `string'

Discussion in 'UGUI & TextMesh Pro' started by ashleyjamesbrown, Mar 18, 2019.

  1. ashleyjamesbrown

    ashleyjamesbrown

    Joined:
    May 23, 2018
    Posts:
    10
    Cannot implicitly convert type `TMPro.TextMeshProUGUI' to `string'

    Error message and im most likely doing the wrong method. c#

    Im trying to extract the actual text from a tmpbox into a string so i can use it checking against a list.

    I had tried getting the m_text but its protected and no method.

    Any help much appreciated. I just cant quite figure the syntax.

    Code (CSharp):
    1. public TextMeshProUGUI locationDisplayName;     // the display box
    2.  
    3. public List<string> locsFound;
    4.  
    5. public void addToList(TextMeshProUGUI tmpName){
    6.  
    7.  
    8.         string name = tmpName.text();
    9.         Debug.Log (name);
    10.  
    11.  
    12.  
    13.         if (locsFound.Contains(name)==true ){
    14.             //do nothing as it already exsists
    15.          
    16.         }
    17.         else {
    18.  
    19.             //get teh string name and add it to list
    20.             locsFound.Add(name);
    21.          
    22.         }
    23. }
     
    Last edited: Mar 18, 2019
    testersuji and AndresDavidala like this.
  2. ashleyjamesbrown

    ashleyjamesbrown

    Joined:
    May 23, 2018
    Posts:
    10
    Edit: fixed
    line 8 is correct and works for anyone interested ill leave the post up.

    Code (CSharp):
    1. string name = tmpName.text();