Open combobox from code

Hi guys,
I am trying to open a UComboBoxString from code or blueprint without any input but with a command received over TCP instead! Is there any way this is possible?

thanks!

is it not possible? i thought OnOpening.Broadcast(); would work but it doesnt.
it seems kinda odd since i can change values via code but not open it

OnOpening.Broadcast(); does not cause the combobox to open, it is there to notify all registered listeners that the box was just opened. If you look at UComboBoxString’s implementation you’ll notice that it uses the Slate SComboBox widget internally. If you now inspect SComboBox and its parent classes you’ll eventually come across the lines of code where input is handled to open and close the box. This uses the SetIsOpen method of SMenuAnchor which SComboBox (indirectly) derives from.

You should be able to figure out the rest. One last thing though. UComboBoxString::MyComboBox is protected and there’s no getter that I can see so you may have to customize your engine a bit so you can get access to it.

I extended the Button to expose it publicly so I could click it and flip hover states with the controller, called it SimButton. A similar thing would work here. I chose to do that instead of modifying the base class.

I think that all the GUI functionality should have control functions in at the base class instead of assuming that it will always be a mouse interaction, but it was like that in UE3 with ScaleForm. This would make it much easier to add GamePad support for UI as well as TutorialMode where you want to have scripted UI behavior, and as well networked control like this thread is asking about.

thanks for your help guys!
i actually am using a derived custom combobox, so i can access the MyComboBox->SetIsOpen(true) function. however nothing happens when i call the method… the MyComboBox->IsOpen() state also does not change

i as a programmer who only recently switched to unreal, find it kind of odd that there is no real documentation on coding in ue.

After a long fuss with inheriting UComboBoxString and SComboRow, I settled on the simple solution of setting focus to the ComboBox and simulating a button press:

FKeyEvent SimulatedKey(EKeys::Virtual_Accept, FModifierKeysState(), 0, false, 0, 0);
FSlateApplication::Get().ProcessKeyDownEvent(SimulatedKey);
1 Like

Your solution works, but it does not invoke the same behaviour as when triggering the dropdown with a mouse click. With mouse click, it automatically places the focus on the first combobox option, with your solution it does not and causes gamepad navigation to immediately collapse the combobox again.

Got any idea why?

I don’t know what exactly the difference is but there’s definitively alot of stuff happening under the hood within Slate outside of the individual widget implementations.
Specifically the processing of the FReply in https://github.com/EpicGames/UnrealEngine/blob/46544fa5e0aa9e6740c19b44b0628b72e7bbd5ce/Engine/Source/Runtime/Slate/Private/Framework/Application/SlateApplication.cpp#L3095 and the key/pointer event handlers in FSlateApplication themselves may cause various state changes. For example the SComboButton (base class of SComboBox) typically calls SetUserFocus on the reply https://github.com/EpicGames/UnrealEngine/blob/d11782b9046e9d0b130309591e4efc57f4b8b037/Engine/Source/Runtime/Slate/Private/Widgets/Input/SComboButton.cpp#L154 which is most likely necessary for the gamepad navigation inputs to be processed so that they navigate the options of the ComboBox.