Hi,
I have a widget, where I show image files from an ImgMediaSource. Works well.
Then I have a custom, second widget (named UI_ImageViewer), where I show the same ImgMediaSource. This is shown in a second window and works well until I restart the Unreal Editor. Then the ImgMediaSource variables of UI_ImageViewer are reset to Type “Object”. This happens every time I restart.
ErrorLog:
Content/UI/UI_ImageViewer.uasset' failed to load '/Script/ImgMedia': Can't find file.
The UI_ImageViewer is a BP child of a widget (u_widget). The u_widget is a member of a custom c++ UObject and is shown in a separate SWindow. I think there is the cause of the problem. Initialization? I saw solutions which use a Custom HUD to create a second window. Is this mandatory?
Here is my code to create the second window and the root widget:
header:
UCLASS(Blueprintable)
class MY_APP_API USecondScreenHandler : public UObject
{
GENERATED_UCLASS_BODY()
public:
UFUNCTION(BlueprintCallable, Category = "SecondScreenHandler")
bool createWindowAndWidget(int offset_x, int offset_y, int width, int height, bool topmost);
UFUNCTION(BlueprintCallable,Category="SecondScreenHandler")
void destroy();
UFUNCTION(BlueprintCallable,Category="SecondScreenHandler")
void bringWindowToFront();
public:
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "SecondScreenHandler")
TSubclassOf<class UUserWidget> u_widget_subclass;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "SecondScreenHandler")
UUserWidget* u_widget;
private:
TSharedPtr<class SWidget> s_widget_ptr = nullptr;
TSharedPtr<class SWindow> s_window_ptr = nullptr;
};
source:
USecondScreenHandler::USecondScreenHandler(const FObjectInitializer& ObjectInitializer) : Super(ObjectInitializer)
{
static ConstructorHelpers::FClassFinder<UUserWidget> class_finder(TEXT("WidgetBlueprint'/Game/UI/UI_2_Main'"));
if (class_finder.Succeeded())
{
init = true;
u_widget_subclass = class_finder.Class;
}
else
{
u_widget_subclass = nullptr;
}
}
void USecondScreenHandler::destroy()
{
u_widget->Destruct();
s_widget_ptr.Reset();
if (s_window_ptr.Get() != nullptr)
{
s_window_ptr->RequestDestroyWindow();
}
s_window_ptr.Reset();
}
void USecondScreenHandler::bringWindowToFront()
{
s_window_ptr->BringToFront(true);
}
bool USecondScreenHandler::createWindowAndWidget(int offset_x, int offset_y, int width, int height,bool topmost)
{
if (u_widget_subclass == nullptr)
{
return false;
}
if (s_window_ptr.IsValid())
{
s_window_ptr->RequestDestroyWindow();
s_window_ptr.Reset();
}
s_window_ptr = SNew(SWindow)
.IsTopmostWindow(topmost)
.AdjustInitialSizeAndPositionForDPIScale(false)
.AutoCenter(EAutoCenter::None)
.Title(FText::FromString(TEXT("OEBB Weststrecke Info")))
.ClientSize(FVector2D(width, height))
.ScreenPosition(FVector2D(offset_x, offset_y))
.CreateTitleBar(false)
.SizingRule(ESizingRule::FixedSize)
.IsInitiallyMaximized(true)
.SupportsMaximize(false)
.SupportsMinimize(false)
.HasCloseButton(false);
FSlateApplication::Get().AddWindow(s_window_ptr.ToSharedRef());
// create the widget object and add it to the window
u_widget = CreateWidget<UUserWidget>(GetWorld()->GetFirstPlayerController(), u_widget_subclass);
s_widget_ptr = u_widget->TakeWidget();
s_window_ptr->SetContent(s_widget_ptr.ToSharedRef());
return true;
}
Maybe someone can point me to the problem. Thanks very much in advance.