Hello dear community!
I am creating an UI for a dialogue system. The dialogue menu widget gets created and, depending on the state of the dialogue, new answer options get constructed or removed based on the available answers.
My problem is the following:
When my I go to an NPC, open the dialogue menu the widget has no focus - I have to click the window so it receives focus, so I can click the options or user there hover events.
What I do behind the scenes is the following:
My HUD class creates my dialogue menu at start.
To open it, my HUD class adds it to the viewport and the Dialogue initializes. Afterward the input mode get set.
When the dialogue initializes itself, it constructs the necessary dialogue options widgets (Texts with buttons which are focussable), adds them to the container and sets the focus on the first one.
Now the interesting thing: When I set the Input mode (with the focus on the very same constructed option widget) in an event with a delay after this whole process, it works flawless!
Therefore: why does this hack work and why can’t I set the focus on the widgets directly after their creation? And if it does not work, why do I receive no errors or warnings?