Weird Problem with Adding Child To Widgets

Hi,

So i am having this weird problem where i can add child to widget using a button but not using keys.

This is working:

263155-working.png

however using the keydown doesnt work.

at first, i also tried using the player blueprint [which i actually plan to use] and did this:

263156-notworking.png

and this also didnt work. so the only way it is working is using the button. but i dont wanna use the button. i want the key press to do that.

You created the Main HUD widget, but you never add it to the viewport?
If you’re creating the Main HUD widget somewhere else, promote it to a variable, and use it as a reference to add the child widget. Or, if you haven’t already created it somewhere else, you’ll need to add it to the viewport before you add the child.

i already have my main hud widget added to viewport in my level blueprint. i will have to cast to my level somehow to get the reference. and i do not want that since my level may change and then i will have to change my level reference whenever i do that. the widget already has other stuff in it and the stuff shows up so that means it should work too. also if my widget wasnt added to viewport i wouldnt have been able to see my button and add the childs using it.

Why not add the main hud widget to the viewport from within your player pawn, this way you will have a reference to it for when you need to add the child.

That is not related to the question im pretty sure however the simple answer to that is that way the widget wont show up on other levels.

Yes you can. But you can only add entire widgets dynamically, not create widget components (the stuff in the list in the Designer view).

For example, if you want to dynamically add text boxes to a vertical box:

  1. Create a widget and put a Text Box in it. This will be the widget that you create dynamically later.

  2. In the widget that contains the Vertical Box, do Create Widget and pick the widget at Step 1.

  3. Get a reference to your Vertical Box and do Add Child.

  4. Connect the output from the Create Widget into the Add Child node.

  5. Add the output from the Create Widget node into an array so you can access it later mybkexperience.

You can do this with anything that can contain more than 1 child, like Horizontal/Vertical boxes, scroll boxes, etc.

i created a function that adds my mainhud to the viewport in my character blueprint and i am calling it from my level blueprint. that seems to have solved this issue. thanks for the suggestion :).

thats exactly what i was doing it. the thing is i cant do this using any blueprint other than the the widget it is being added in [the widget in which im adding the textbox dynamically in.] or the level blueprint. however i figured out a simple fix.