.h:
- // Fill out your copyright notice in the Description page of Project Settings.
-
- #pragma once
-
- #include "CoreMinimal.h"
- #include "GameFramework/HUD.h"
- #include "MyHUD.generated.h"
-
- /**
- *
- */
- UCLASS()
- class FLOATINGCUBE_API AMyHUD : public AHUD
- {
- GENERATED_BODY()
-
- public:
- virtual void BeginPlay() override;
- AMyHUD();
-
- UPROPERTY(EditAnywhere, BlueprintReadWrite)
- TSubclassOf
userWidget; -
- UPROPERTY()
- UUserWidget* refWidget;
- };
.cpp:
- // Fill out your copyright notice in the Description page of Project Settings.
-
-
- #include "MyHUD.h"
- #include "Blueprint/UserWidget.h"
-
- AMyHUD::AMyHUD() {
-
- }
-
- void AMyHUD::BeginPlay() {
- refWidget = CreateWidget
(GetWorld(), userWidget); - if (refWidget != nullptr) {
- refWidget->AddToViewport();
- }
- }