how to spawn a new text block in widget

I am trying to achieve a text based list of names that keep adding to the list as the player inputs more names to it in the input field, shown in the middle of the screen.

The names should appear below, as shown in the picture “Test”, and as the player adds a new name, that name appears in the list as well. Right now I have only one text block to show the player the last given index in the array that he entered to the input field, but I want the list to grow with more names as the player adds them.

Here is my code so far: The player writes a name in the input field, it goes to “player” array, the player array then shoots to existing text block below the input field to display the given name. Right now though, if the player adds a new name, the text block changes to the last index, just to show that it actually is taking items from the array.

My current problems with the code are:

  • The “print string” (log) does not print the length of my array to me in gameplay. I want to see how many items I have in my array just for troubleshooting.

  • I don’t know how to add/spawn a new text block as the player inputs a name in the field.

Also a follow up question is how I can make the input method go through the plus button shown on the right side of the input field, instead of pressing enter.
Note this game is a mobile game

  1. You can create new Widget containing only text block you need. Then you can add it to main widget through “Add Child” node.
  2. You should bind “OnClick” event from your button to some event in main widget. This allows you to do anything you want on button click.

This is not quite what I am looking for. There has to be a more simpler and firm way to make it so that each time the player types a player name, it adds to the list as its own text block. What you suggested is kinda a work around my idea, which could work, why not, but I don’t like to do things in that sense. I bet there is a command in unreal engine to create something and add it to a list as a visible object/text.

I’m looking for this as well. Create Widget doesn’t allow the ‘common widgets’ to be created.

Since this doesn’t have an answer, you’ll want the “Construct object from class” node.

252094-create-object-from-class.png

9 Likes