Replace String in UMG

Hi, i’m trying to use the Replace string node in UMG. I have an String Array connected to the replace, The goal is to change the text in my widget to something random from the list. When i tests this ingame it seams that it is changing between all the text in the array really fast. i would like it to change to one of the strings and stop. i have tried do once but i don’t work for me.

thanks for any help!

Sounds like you’re doing this during tick or you’re using function binding for this. What is supposed to trigger the text change in your case?

I’m using function binding. The text is part of a widget I display on an actor. I create the actor using a button press. I would like the string to change once it is created

I would like the string to change once
it is created

Bindings update every frame, so you’re randomly changing the text 60 times a second (or more!).

It’s a good idea to get used to an Event based system:

  • clear the binding
  • flag the the text box as variable (top of the details panel - isVariable)
  • in Construct event, get the text box you flagged as a variable and set its text to the result of the random node pulling it from your string array

Construct fires when the widget is created, only once.


Alternatively:

  • create a text / string variable in the widget (no need to flag the text box as one anymore) and bind it to that text box (instead of a function, the variable will appear on the list)
  • set that variable in the Construct or…
  • …expose that variable on spawn (another tick box when the variable is selected) and feed the Create Widget node ready text - it will have an extra pin once refreshed

Do tell if you’re having issue implementing this.

How would you go about linking this together?

Is the card description the text box reference? Pull a wire from it and Set Text.
The 1st one, you do not need the 2nd one.

I cleared the binding and made it an Variable. in the construct panel i dragged it out but i’m confused on how to hook it up. My output is a string and the Text only takes text object reference.

270189-capture.png

Try dragging a wire from here and search for Set Text. You should end up with this:

Essentially, every small widget element is an object, you get access to it via an exposed reference variable and modify the object somehow - Set its Text in this very instance.

Some widgets (mostly panels that can house children) are exposed by default, some may need to flagged as isVariable manually.

Hope it makes sense!

That did the trick! thank you good sir!

Awesome, good luck with the rest!