方法一
在蓝图关卡中将蓝图控件添加到视口:

方法二
在PlayerController类中创建并添加到视口:
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/PlayerController.h"
#include "TPSPlayerController.generated.h"
UCLASS()
class NETEASETPS_API ATPSPlayerController : public APlayerController
{
GENERATED_BODY()
public:
UPROPERTY(EditAnywhere, BlueprintReadWrite)
TSubclassOf<UUserWidget>HUDAssert;
UUserWidget* HUD;
protected:
virtual void BeginPlay() override;
};
#include "TPSPlayerController.h"
#include "Blueprint/UserWidget.h"
void ATPSPlayerController::BeginPlay()
{
Super::BeginPlay();
if (HUDAssert)
{
HUD = CreateWidget<UUserWidget>(this, HUDAssert);
}
if (HUD)
{
HUD->AddToViewport();
}
}
然后新建PlayerController子类蓝图并指定控件蓝图,在世界场景中指定该PlayerController蓝图类。

参考:https://blog.csdn.net/Norths_/article/details/123105415

本文介绍在虚幻引擎4(UE4)中两种添加HUD(User Interface)的方法:一是通过蓝图关卡添加蓝图控件到视口;二是通过PlayerController类创建并添加到视口。示例代码展示了如何在开始播放时实例化指定的HUD断言。

4121

被折叠的 条评论
为什么被折叠?



