【问题标题】:How to add widget in Unreal Engine如何在虚幻引擎中添加小部件
【发布时间】:2020-07-16 09:15:03
【问题描述】:

如何在虚幻引擎中将小部件添加到屏幕? 由于某种原因,变量blackLinesWidgetClass 始终为空。

    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();
    }

【问题讨论】:

  • 抱歉,这不是很有帮助,但我一直远离尝试与 C++ 中的小部件交互,而是使用蓝图。这些问题要少得多。

标签: c++ widget unreal-engine4 game-development


【解决方案1】:

看起来 UE4 没有从您提供的类引用路径中成功加载该类。尝试在此处添加_CUI/blackLines.blackLines_C'"

【讨论】:

    【解决方案2】:

    这对我有用

    .h

    UPROPERTY(EditAnywhere) TSubclassOf<UUserWidget> widgetBlackLines;
    UUserWidget* widgetBlackLinesInstance;
    

    .cpp

    void AAct_31::BeginPlay()
    {
        widgetBlackLinesInstance = CreateWidget<UUserWidget>(GetWorld(), widgetBlackLines);
        widgetBlackLinesInstance->AddToViewport();
    }
    

    【讨论】:

      猜你喜欢
      • 2021-07-06
      • 2020-03-26
      • 2018-11-28
      • 2020-10-02
      • 1970-01-01
      • 2016-12-28
      • 1970-01-01
      • 2016-06-03
      • 2018-09-01
      相关资源
      最近更新 更多