So I’m trying to add a ComboBox from C++, and this is roughly what’s going on:
SNew(SComboBox<FComboboxItem>)
.OptionsSource(&Options)
.InitiallySelectedItem(CurrentItem)
[
SNew(STextBlock)
.Text(this, &FGOAPModule::GetCurrentKey)
]
However, this part returns an error:
SNew(STextBlock)
.Text(this, &FGOAPModule::GetCurrentKey)
The error reads:
no instance of overloaded function "STextBlock::FArguments::Text" matches the argument list
argument types are: (FGOAPModule *, FText (FGOAPModule::*)())
object type is: STextBlock::FArguments
However, I’m cross-referencing with this, and I can’t see why it’s throwing an error despite being virtually identical. Additionally, STableViewListing in the source files use .Text in the same way.
Okay, so I realized one thing I’m doing wrong. Apparently, I need to pass .Text a const.
So the function I’m trying to call is this…
.h
FText GetCurrentKey() const;
.cpp
FText FGOAPModule::GetCurrentKey() const
{
if (CurrentItem.IsValid())
{
return FText::FromString(*CurrentItem);
}
return LOCTEXT("InvalidComboEntryText", "<<Invalid option>>");
}
However, I’m getting a slew of weird errors now that I try to figure the origin of…
Nevermind, I figured it out.
.Text can take the function arguments, but the function needs to be const, as shown above. I.e
FText FGOAPModule::GetCurrentKey() const
{
if (CurrentItem.IsValid())
{
return FText::FromString(*CurrentItem);
}
return LOCTEXT("InvalidComboEntryText", "<<Invalid option>>");
}
Now my next problem was that I would get an error when compiling. It was related to delegates, though I’m not privvy to exactly why. Thanks to this link I discovered I needed to make this change…
Before
.Text(this, &FGOAPModule::GetCurrentKey)
After
.Text_Raw(this, &FGOAPModule::GetCurrentKey)