Set a Value in my TextBox

Hi, Everybody. Everything ok.

I need when my button is clicked set a value from a variable to my TextBox. How could I make it ?

Thank you

Bind the text box to a value variable link string. Depending on what it’s going to shoe… Then give the button an action when clicked to set that variable. Need more info but that’s the general idea.

Hi Imph1del, Nice to meet you.

So, I have 2 widgets, the first widget it has a TextBox and the second widget it has a button. I need when I clicked in the button from second widget, change the value of the TextBox from First widget

Thank You

make the text a variable, and inside the OnClicked Event of the Button, get the text variable and use the SetText(text) node to change it´s value.

Yes, I tried that, but it doesn’t work. Please, could you post a blueprint screen?

Thank you

I’m going to suggest you run through a tutorial from unreal.

I’m going from memory here but.

On the text you want to change it’ll have a value and next to it Bind create binding now it’ll open a get text you need A variable. So on the left add s new variable of type you want it to be I’ll assume string.

Now on the button select it and scroll down to click to add event… On click then drag out a set to the var you just made and input the string your changing it to.

Hope you understand.

You are simply making a on click command to set the value of the binded value or the text.

I have made this in one widget, If you need to use two widgets for any reason you can easily change it.

  1. I have made a text variable and wrote what i want the text to change to.

  2. I have put a text block on the widget and made it a variable

  3. I put a button on the widget

  4. I clicked on the button and click the on clicked event

  5. i got my text block variable and set text (text) and put the text variable into it.

fa8aaaf5b54e5a613941e829f06a6013.png

  1. I made it show on screen when the game is played.

When the button is pressed the text will now change, If you want it so you can write your own message in there from in-game just tell me and i will show you how to do it.

I have a doubt When I call the TextBlock from the First Widget, I need to define a Target, What target is that ?

You don’t need to set text. Your only setting the variable. If you bind the text box to get its value from the variable it will update when it’s changed.

I’m trying that, but It doesn’t work.Look:

I set a text to test when I press the button:

What it’s wrong ?

I see 2 issues with you setup.

  1. You are not storing references to the widgets - if you remove one from the viewport at some point and no valid reference is present, that widget will get automatically garbage-collected and you will lose it
  2. You are not adding the first widget to the viewport - that’s why it’s not showing

Consider the following:

Here I create the *Second *widget, in this case it’s in the Controller but that does not really matter; I also set up a reference so I can manipulate that widget later as well as add and remove it from the viewport easily and without risking having it destroyed:

A button in the second widget creates the first widget, adds a reference, changes the text, and finally adds it to the viewport:

Regarding what @Inph1del said about binding, he is right when he says there’s more than one way of sending data to a widget.
Consider familiarising yourself with this guide:

It describes 2 ways of widget property binding as well as the SetText method you’re using (Event Driven with extras, Dispatchers and other bells&whistles). I wouldn’t demonise its use, it’s definitely a valid way of sending data in certain scenarios. The guide really describes it much better than I ever could.

Hope it helps.