I have a class derived from UWidget, defined as follows: class UMGSPLINE_API UDrawWidget final : public UWidget
. I want to dynamically create an instance of this UWidget during runtime, but I encountered a compilation error when trying to use CreateWidget. Are there any other ways to create a UWidget in C++? Below is my code:
UDrawWidget* pDrawLine = CreateWidget<UDrawWidget>(GetWorld());
pDrawLine->SetSplineMaterial(pDotLineMaterial);
pDrawLine->RemoveAllSplinePoint(true);
m_pDrawLinePanel->AddChild(pDrawLine);
m_bTopTrackPanel ? Cast<UCanvasPanelSlot>(pDrawLine->Slot)->SetSize(FVector2D(230.0f, 400.0f)) : Cast<UCanvasPanelSlot>(pDrawLine->Slot)->SetSize(FVector2D(300.0f, 200.0f));
m_arrCoordYWidget.Add(pDrawLine);
pDrawLine = CreateWidget<UDrawWidget>(GetWorld());
pDrawLine->SetSplineMaterial(pWhiteLineMaterial);
pDrawLine->RemoveAllSplinePoint(true);
m_pDrawLinePanel->AddChild(pDrawLine);
m_bTopTrackPanel ? Cast<UCanvasPanelSlot>(pDrawLine->Slot)->SetSize(FVector2D(230.0f, 400.0f)) : Cast<UCanvasPanelSlot>(pDrawLine->Slot)->SetSize(FVector2D(300.0f, 200.0f));
m_arrCoordXWidget.Add(pDrawLine);