How to use OnTextCommitted

Sorry for a probably simple question but I’m getting confused and can’t get how to use the OnTextCommitted function on an SEditableTextBox widget. I would like to make it so that whatever is committed into the textbox changes the name of a selected character in the scene. I already have access to the character data and can even change the name directly, I’m just wondering how I can instead change it through the OnTextCommitted function.

void SYourWidget::Construct(const FArguments& InArgs)
{
ChildSlot
[
SNew(SEditableTextBox)
.OnTextCommitted(this, &SYourWidget::OnCharacterNameCommitted)
];
}

void SYourWidget::OnCharacterNameCommitted(const FText& InText, ETextCommit::Type InCommitType)
{
    // Set your character name from InText
}
1 Like

Hm I’ve tried this but I always get errors from DelegateSignatureImpl_Variadisc.inl file, line 155. Such as ‘AsShared’ it not a member of my class.

I forgot to mention that all of this functionality is in an editor module, I’m not dealing with runtime at all, would it still be the same method?

Is your class derived from SWidget (even indirectly), or are you trying to use Slate stuff inside a non-Slate class?

Non slate, derives from IModuleInterface. It’s a replica of the auto-generated code that you get when you create a new ‘standalone window’ plugin when you go to Plugins->New. Except it’s in an editor module not a plugin (to access project-specific classes)

Still learning with all this engine architecture related code so this lower-level stuff is not familiar to me :confused:

function:

TSharedRef<SDockTab> FMyGameEditorModule::OnSpawnPluginTab(const FSpawnTabArgs& SpawnTabArgs)
{

    
    FText WidgetText = FText::Format(
        LOCTEXT("WindowWidgetText", "{0} "),
        FText::FromString(TEXT("Random Startup Text"))
        );

    return SNew(SDockTab)
        .TabRole(ETabRole::NomadTab)
        [
            SNew(SBox)
            .HAlign(HAlign_Center)
            .VAlign(VAlign_Center)
            [
                SNew(SEditableTextBox)
                .Text(WidgetText)
                .OnTextCommitted(/*here i should call a function that uses character to setname*/)
            
            ]
        ];
}

I should note that I have access to whichever character I have selected in the editor window when this code runs. (yes I believe I pretty much want to replicate some of the details panel functionality)

Alright, Ill get working on that, Thanks for the help!

Okay, trying to bind to a function in your module isn’t great, so what I’d do here is make a custom widget deriving from SCompoundWidget and then set it up to contain an SEditableTextBox like in my example above.

You would then pass into this widget (using its construction arguments) a pointer/reference to whatever you need to call to update the character name, and then use this custom widget type in place of your SEditableTextBox in FMyGameEditorModule::OnSpawnPluginTab.

Hey Penanito, I’m trying to accomplish an identical task in the editor. I know this thread is a couple months old, but I’m just wondering if you ever managed to create that custom widget deriving from SCompoundWidget (as suggested by Jamie). If so, could you give some tips and/or share the source for that custom widget?

Learning to extend the editor is a lot more tedious than I initially thought. Thanks :slight_smile:

Sure thing, widget definition in .h:

class MyWidget: public SCompoundWidget
{
public:

    SLATE_BEGIN_ARGS(MyWidget) :
    {}
    SLATE_END_ARGS()


    void Construct(const FArguments& args);
};

main function in .cpp

void SDRWidget::Construct(const FArguments& InArgs)
{
    ChildSlot
        [
            SNew(SHorizontalBox)
            + SHorizontalBox::Slot().HAlign(HAlign_Fill)
            [
                SNew(STextBlock)
                .MinDesiredWidth(125.0f)
                .Text(FText::FromString("Custom Widget"))
            ]
        ];
}

May have missed some syntax specifics but that should be the basics.
then you can create this widget as if it were any other. Just make sure wherever you’re calling it from has MyWidget.h included.

I use an editor module (essentially the same as the basic plugins UE4 creates for you), so I just return a new tab with that widget when the you open the custom editor tool.

TSharedRef<SDockTab> MyEditorModule::ReturnCustomWidget(const FSpawnTabArgs& SpawnTabArgs)
{
    return SNew(SDockTab)
        .TabRole(ETabRole::NomadTab)
        [
            SNew(SBox)
            [
                SNew(MyWidget)
            ]
        ];
}