I need to find UClass and use it in BeginPlay.
Now I write constructor and save UClass in field:
AMyHUD::APuzzleHUD()
{
static ConstructorHelpers::FClassFinder<UObject> widgetClass(TEXT("/Game/UI/GameUI.GameUI_C")); // find class by url
MyUIWidgetClass = *widgetClass.Class; // save to private field
}
void AMyHUD::BeginPlay()
{
MyUIWidget = CreateWidget<UUserWidget>(GetWorld(), MyUIWidgetClass);
MyUIWidget->AddToViewport();
MyUIWidget->SetVisibility(ESlateVisibility::Visible);
}
But I would be more convenient to use FClassFinder in BeginPlay or use as field of class.
- Why FClassFinder can’t be use in other methods?
- Why if I write it as field of class:
private:
ConstructorHelpers::FClassFinder<UObject> widgetClass(TEXT("/Game/UI/GameUI.GameUI_C"));
I get error: error C2059: syntax error : ‘string’ ?