I have tried creating a custom UUserWidget
that already has its UCanvasPanel
populated when creating a new instance of the class but only seem to see it in the details panel and not the hierarchy. From what I can see using
ConstructWidget()
will create the widget, but not fulfil the binding requirements or show it in the hierarchy. Instead I can see it in the details panel with the correct name (I was testing various UWidgets to see if they would show, have not included them in code example for simplicity):
Here’s my code;
UUserWidget.cpp:
UFluidDialogueBox::UFluidDialogueBox(const FObjectInitializer& ObjectInitializer) : Super(ObjectInitializer)
{
}
void UFluidDialogueBox::NativeConstruct()
{
Super::NativeConstruct();
}
void UFluidDialogueBox::NativePreConstruct()
{
}
void UFluidDialogueBox::SynchronizeProperties()
{
if (WidgetTree)
{
Canvas = WidgetTree->ConstructWidget<UCanvasPanel>();
if (Canvas)
{
WidgetTree->RootWidget = Canvas;
}
WidgetTree->Modify();
}
AddToViewport();
Super::SynchronizeProperties();
}
UUserWidget.h
#pragma once
#include "CoreMinimal.h"
#include "Runtime/UMG/Public/UMG.h"
#include "Blueprint/UserWidget.h"
#include "FluidDialogueBox.generated.h"
UCLASS(BlueprintType,Blueprintable)
class FLUIDDIALOGUESYSTEM_API UFluidDialogueBox : public UUserWidget
{
GENERATED_BODY()
UFluidDialogueBox(const FObjectInitializer& ObjectInitializer);
protected:
virtual void NativeConstruct() override;
virtual void NativePreConstruct() override;
virtual void SynchronizeProperties() override;
UPROPERTY(EditAnywhere, BlueprintReadWrite, meta = (BindWidget))
UCanvasPanel* Canvas = nullptr;
};
The end result I’m looking upon making a BP version of the extended UUserWidget
is this:
Thanks!