Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Change value of TextField programmatically

Discussion in 'UI Toolkit' started by AdamRamberg, Oct 27, 2021.

  1. AdamRamberg

    AdamRamberg

    Joined:
    Dec 8, 2016
    Posts:
    22
    Hi everyone!

    Is is possible to change the value of a runtime UIElements TextField programmatically? Setting the property `value` seems to set the internal value, but doesn't rerender the TextField. Is there a way to set the value and then tell UIElements to rerender the TextField with the updated value?

    Thanks,
    Adam
     
  2. martinpa_unity

    martinpa_unity

    Unity Technologies

    Joined:
    Oct 18, 2017
    Posts:
    360
    Hey!
    TextField.value
    should be the way to go. The internal value will set the input field, which will trigger a version change if the text is different.

    Is this for editor or runtime use-cases?

    What version of Unity are you using (and packages if you are using the ui/builder packages)?
     
  3. AdamRamberg

    AdamRamberg

    Joined:
    Dec 8, 2016
    Posts:
    22
    Thanks for the swift response! It's a runtime use case. However, I think that I might just have goofed up on my end. Made a simple test where I removed some of the complexties of my code and it seems to work. Sorry for reporting a none-issue.
     
  4. martinpa_unity

    martinpa_unity

    Unity Technologies

    Joined:
    Oct 18, 2017
    Posts:
    360
    No worries! :)