Hello, iam new to the C++ part of UE4.
I made a standalone window plugin.
It is for spawning static mesh actors according to a text file with coordinates.
It works fine already but i want it to be more intuitive.
So i want , when the user selects an asset from the content browser, that the asset name is shown in the plugin window.
I have this kinda working already, BUT, only if i close and reopen the plugin window.
So how do i update .Text(WidgetText) whenever a new Asset is selected in the Content Browser?
Main window function:
TSharedRef<SDockTab> FXSI2UE4Module::OnSpawnPluginTab(const FSpawnTabArgs& SpawnTabArgs)
{
//Get Current Selection for displaying
TArray<FAssetData> Items = CBGetSelectedItems();
FName FirstItem;
FText WidgetText;
if (Items.IsValidIndex(0)) // Prüfen ob etwas ausgewählt out of bound crash
{
FirstItem = Items[0].ObjectPath;
WidgetText = FText::Format(
LOCTEXT("WindowWidgetText", "Selected Item: {0}"),
FText::FromString(FirstItem.ToString())
);
}
else
{
WidgetText = FText::Format(
LOCTEXT("WindowWidgetText", "Selected Item: {0}"),
FText::FromString("None")
);
}
// Window Layout -----------------------------------------------------------------
return SNew(SDockTab)
.TabRole(ETabRole::NomadTab)
[
SNew(SScrollBox)
+ SScrollBox::Slot().Padding(10, 5)
[
SNew(SVerticalBox)
+ SVerticalBox::Slot().HAlign(HAlign_Center).VAlign(VAlign_Center)
.MaxHeight(60.0f)
[
SNew(SButton)
.VAlign(VAlign_Center)
.HAlign(HAlign_Center)
.Text(FText::FromString("Spawn Instances"))
.ToolTipText(FText::FromString("Spawn Static Mesh"))
.DesiredSizeScale(FVector2D(100.0f, 60.0f))
.OnClicked_Raw(this, &FXSI2UE4Module::OnButtonClicked)
]
+ SVerticalBox::Slot().HAlign(HAlign_Center).VAlign(VAlign_Center)
.MaxHeight(100.0f)
[
SNew(STextBlock)
.Text(WidgetText)
]
]
];
}
Selected assets function:
TArray<FAssetData> CBGetSelectedItems()
{
TArray<FAssetData> AssetDatas;
FContentBrowserModule& ContentBrowserModule = FModuleManager::LoadModuleChecked<FContentBrowserModule>("ContentBrowser");
IContentBrowserSingleton& ContentBrowserSingleton = ContentBrowserModule.Get();
ContentBrowserSingleton.GetSelectedAssets(AssetDatas);
return AssetDatas;
}