Search Unity

Question How can I pass a string as a variable to a TMP_InputField at runtime in Unity?

Discussion in 'UGUI & TextMesh Pro' started by hanskovi, Jul 24, 2020.

  1. hanskovi


    Jan 14, 2018
    In my script I set a string to a variable named output_formula. The future purpose is to change any typed digit in the formula to a subscript. For now I’m only testing and run into this problem.

    The script is attached to the On Value Changed(string) part of a TMP Input Field as shown in the image.

    Schermafbeelding 2020-07-24 om 14.42.17.png

    Schermafbeelding 2020-07-24 om 15.04.32.png

    When I run all this and type a digit (eg the 2 in H2O) in the TMP Input Field, Unity hangs and shows no digit. In fact, it seems that the entire script doesn’t run since any Debug.Log’s I try (see script) don’t display in Untity’s console.

    When I change the variable output_formula into a string like “output_formula” (see the comments in the attached script) the text in the input field becomes “output_formula” when I type a digit which indicates that the script must work.

    I obviously do something wrong :) Can anybody explain to me what exactly I’m doing wrong here and help me to solve this issue ?