Code that gets executed when you select a combobox item

I’m having trouble finding examples of how to execute code when a combobox item is selected. Currently I have a working combobox with items:


TSharedPtr <FUICommandInfo> SetResAuto;


UI_COMMAND(SetResAuto, "Auto", "Set resolution of baked textures automatically", EUserInterfaceActionType::Button, FInputChord());


ResMenuBuilder.AddMenuEntry(FOctaneRenderPluginCommands::Get().SetResAuto,	 NAME_None, LOCTEXT("ResAutoString", "Automatic"));

So, how do you get this to execute code when an item is selected?

I believe you can put an if statement in your PostEditChangeProperty() function that checks if the box is ticked or not (bool)? Is the box in your plugin’s module file or an actor in your plugin?

The box is in the plugin’s module file. What’s the point of the command setup if there’s no command to execute? Also I’m not sure comboboxes work like that, they only look like drop-downs. Once an item is chosen it doesn’t change the state of the control, it should just execute a command. Oh, I’ve been using an SComboButton, not a box. Whoops.

I see SComboBox inherits from SComboButton and I probably do want an actual combobox. Back to the drawing board I guess. :slight_smile:

I am also learning UE4 C++ by creating a plugin, I have successfully set a bool checkbox to run code depending on the toggle in PostEditChangeProperty(), in your case I believe you want a switch statement in postEditChangeProperty() that checks what item is selected in the combobox? Again, I am not a professional.

I don’t think PostEditChange applies to slate elements, it’s more of an actor thing.

As far as slate goes you can bind methods to the SNew() command, which is probably what I want. It’s just about finding the right one. The docs suggest that OnButtonClicked() should exist but VS rejects it completely. Hmm.

in my editor mode where I create my slate structure I have a:

struct Locals{ static FReply OnButtonClick(){ Your code here } };

In my slate structure I have:

SNew(SButton)
.Text(TEXT(“Button Label”))
.OnClicked_Static(&Locals::OnButtonClick)

There may be some important bits missing.

Alright, I think the missing lines are meant to look something like this:


FOctaneRenderPluginCommands::Get().SetResAuto.AddRaw(this, &FOctaneRenderPluginModule::OnResMenuClicked);

That’s not valid though, anyone know what it should look like?

Sorry man, OnClicked is an SButton event, doesn’t appear in SComboButton as far as I can tell. The solution is to do with linking commands.

So much layers.

Yeah it’s insane. Surely there were some existing UI drawing frameworks out there that could have been used rather than this completely non-standard nightmare.

Found it, the default plugin setup actually gives you an example:


PluginCommands->MapAction(
    FOctaneRenderPluginCommands::Get().SetResAuto, 
    FExecuteAction::CreateRaw(this, &FOctaneRenderPluginModule::OnResMenuClicked), 
    FCanExecuteAction()
);