I have a widget component displays a Blui widget in the game world. The widget component loads a blueprint that is a copy of one of the Blui examples. The blueprint extends BluWidget; a class that I created to communicate between blueprints and c++.
I create an instance of the widget component in an actor component and the first time I run the game in editor or standalone, it works perfectly fine. However, every time after that, it only loads instantly after I click on the actor holding the component in the editor. This seems to point to a problem with destruction or garbage collection but after trying different things for two weeks, I couldn’t figure out what’s causing it on my own.
Actor component creating the widget component
void UHealthComponent::BeginPlay()
{
Super::BeginPlay();
m_pUiComponent = NewObject<UBluWidgetComponent>(GetOwner());
m_pUiComponent->AttachToComponent(GetOwner()->GetRootComponent(), FAttachmentTransformRules::KeepRelativeTransform);
m_pUiComponent->RegisterComponent();
}
Widget Component
UBluWidgetComponent::UBluWidgetComponent() : Super()
{
static ConstructorHelpers::FClassFinder<UBluWidget> widgetClassFinder(TEXT("/Game/UI/BLUI/BluiWidgetImpl.BluiWidgetImpl_C"));
m_uiClass = widgetClassFinder.Class;
Space = EWidgetSpace::World;
WidgetClass = widgetClassFinder.Class;
DrawSize = FIntPoint(500, 500);
bManuallyRedraw = false;
RedrawTime = 0;
bDrawAtDesiredSize = true;
m_bInitialized = false;
}
void UBluWidgetComponent::BeginPlay()
{
Super::BeginPlay();
if (UBluWidget* pWidget = Cast<UBluWidget>(GetUserWidgetObject()))
{
pWidget->InitBluEye(FVector2D(500, 500), "blui://Content/UI/Default/index.html");
pWidget->SetVisibility(ESlateVisibility::Visible);
}
}
Blueprint init function