[英]How to add SWidgetSwitcher and get/set current widget index in Unreal Engine 4?
[英]How to add widget in Unreal Engine
如何在虚幻引擎中将小部件添加到屏幕? 由于某种原因,变量blackLinesWidgetClass
始终为 null。
FStringClassReference blackLinesWidgeClasstRef(TEXT("WidgetBlueprint'/Game/Blueprints/UI/blackLines.blackLines'"));
UClass* blackLinesWidgetClass = blackLinesWidgeClasstRef.TryLoadClass<UUserWidget>();
if (blackLinesWidgetClass)
{
UUserWidget* blackLinesWidget = CreateWidget<UUserWidget>(this->GetGameInstance(), blackLinesWidgetClass);
if (blackLinesWidget)
blackLinesWidget->AddToViewport();
}
看起来 UE4 没有从您提供的 class 参考路径成功加载 class。 尝试在此处添加_C
: UI/blackLines.blackLines_C'"
。
这对我有用
。H
UPROPERTY(EditAnywhere) TSubclassOf<UUserWidget> widgetBlackLines;
UUserWidget* widgetBlackLinesInstance;
.cpp
void AAct_31::BeginPlay()
{
widgetBlackLinesInstance = CreateWidget<UUserWidget>(GetWorld(), widgetBlackLines);
widgetBlackLinesInstance->AddToViewport();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.