Search Unity

NullReferenceException with textInfo.wordInfo.GetWord()

Discussion in 'UGUI & TextMesh Pro' started by Heckmouse, Jul 1, 2019.

  1. Heckmouse

    Heckmouse

    Joined:
    Nov 7, 2014
    Posts:
    27
    I'm trying to keyword tips in my game using textInfo, when I use a foreach loop on wordInfo to check each word it creates a null reference exception. Any ideas why this might occur?


    upload_2019-7-1_10-17-27.png
     
  2. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    Arrays for these data structures are allocated in blocks which means the array length will rarely match the size of the valid data.

    As such, in order to get the correct # of characters, words, etc. you have to use the textInfo count property. In the case of word count, you would use textInfo.wordCount.
     
  3. Heckmouse

    Heckmouse

    Joined:
    Nov 7, 2014
    Posts:
    27
    Makes sense, thank you Stephan!