Search Unity

Unity UI TextMeshProUGUI updates outside of play mode instead of during play mode

Discussion in 'UGUI & TextMesh Pro' started by EKstemdev, Dec 28, 2018.

  1. EKstemdev

    EKstemdev

    Joined:
    Nov 27, 2018
    Posts:
    2
    Hi

    I am having trouble with Unity's UI input field script and having my function update the text of my UI during play mode.

    - In the input field I have set a call to my function (checkInput) to trigger upon the user changing the value of the input field. In that function there is a check to see if the user inputted a value outside of the specified range. If the value is outside the range, its supposed to send a message in my UI so the user can see.

    The problem is the change occurs AFTER I exit play mode, not during. I'm not sure why I'm getting this behavior. Any insight would be really appreciated.



    Here is a snippet of my function.

    - the "public TextMeshProUGUI errorMsg;" has a reference to a Text UI prefab that has been placed in my hierarchy view.

    - when the user enters a bad value it should change my Text UI to say BAD ARM. However this occurs after I exit out of play mode.

    >> is there some interaction with the input-field's "on value changed" and setting the value of a text element that I'm not doing correctly?

    Code (CSharp):
    1.  
    2.  
    3.  
    4. public TextMeshProUGUI errorMsg;
    5.  
    6.     public void checkInput()
    7.     {
    8.         if (GameObject.FindGameObjectWithTag("inputArm"))
    9.         {
    10.             Debug.Log("INPUT ARM");
    11.             InputField val = GetComponent<InputField>();
    12.             int a = int.Parse(val.text);
    13.  
    14.             if(a > Max || a < Min)
    15.             {
    16.                 Debug.Log("Value must between -10 and 10");
    17.                 errorMsg.text = "BAD ARM";
    18.  
    19.             }
    20.         }
    21. }
     
  2. EKstemdev

    EKstemdev

    Joined:
    Nov 27, 2018
    Posts:
    2
    Never mind I figured out my issue. It has to do with how prefabs are updated in the project view vs the hierarchy view nothing to do with the code.