How do I set a string to something else?

Hello, so I have no idea how to change a string to another string. If for example I have a string where the default value is hello how can I change it to another default value of a different string. Thanks for any help!!

Hi Milloz

Are you talking about just setting the variable?
If so, you just use a variable setter.

If not, could you explain in a bit more detail and perhaps provide an example of what it is you’re trying to do.



Hi thanks! Sorry I was a bit unclear. What I meant but did not write was I want to change the strings default value. If I have two widget blueprints and have a string that was made in the first widget blueprint and set the default value to ‘hello’, and then set the string to something else and then for example print out the string it will show what the string was set to in the first widget blueprint but if I then go into the second blueprint widget and cast to the first one to get the string, the value of the string will be the default and not what I changed it to. Thanks!!!

Hi Milloz

How are you changing / setting the string variable?

In widgets, you can make use of the “PreConstruct” event to set the string variable and it should overwrite the default value which you should then be able to access from the second widget.

Could you give an actual example of what it is you’re trying to achieve i.e. your desired end result, there might be a better way to go about this.


Hi, thank you so much for your help! Yes of course.

I am making a multiplayer game and have made it so you can host or join. If you host then you will write the name of the server and the max players. Then when you click host/start you join the lobby.

In the lobby map I made another UI that basically allows the host to click ready, however, on the lobby UI I want it to show what the server name was called, here are some pictures. The first picture is the ‘create a match UI’, and the second one is the lobby UI. I bound the Text Block on the lobby UI so that it would be equal to the server name, however, it never changes and always stays as its default value.

I tested my problem and when I printed out my server name or if I printed out a variable that was set to server name it would work. (This was on the host UI, when they clicked host match it printed out the variable that got set to the server name) However, when I then looked at my lobby UI the variable that had been set to the server name would be the default value and not what I had set it to. So it works on one UI but not the other, I guessed this was because I had to permanently change its default value.

Thanks for all the help!!!

This is how my blueprints look like. The first picture is me setting and then testing to see if it actually changes(this is in the host UI blueprint) Then the second picture is me binding the Text box to my servername.

Hi Milloz

The bound function “GetServerNText0” Is creating a NEW widget each time the text widget is called so it is resetting to the default value each time because the new widgets it creates will not have the logic called.

Move the “Create Match UI Widget” out of the Getter function (This is very expensive anyway).

Make sure the Match UI widget is only created once and that is the widget in which the name actually gets set. Store a reference to that widget and then you can bind the variable directly without needed the bind getting function.

Hope this helps