How To Set default TextField.Text Programatically?

Is it possible to create a TextField with specified starting text?

TextField m_GameName = this.Q(“game-name”);
m_GameName.text = “My Game”;

gets:

The property or indexer 'TextInputBaseField<string>.text' cannot be used in this context because the set accessor is inaccessible

Try with m_GameName.value = "My Game" instead. I’m not exactly sure why the text accessor is protected. We will have a look.

3 Likes

@mcoted3d I went with m_GameName.SetValueWithoutNotify(“My Game”)

(although tbh not sure how it is different than changing value directly)

SetValueWithoutNotify won’t trigger a ChangeEvent when changed, this is indeed probably what you need in your situation.

2 Likes