Started with FindComponentByClass, but got an error.
.cpp
#include “Tank.h”
#include “Components/WidgetComponent.h”
#include “Math/UnrealMathUtility.h”
#include “GameFramework/Actor.h”
void ATank::BeginPlay()
{
Super::BeginPlay();
CurrentHealth = 100;
Widget = FindComponentByClass UWidgetComponent ();
}
.h
#pragma once
#include “CoreMinimal.h”
#include “GameFramework/Actor.h”
#include “Tank.generated.h”
DECLARE_DYNAMIC_MULTICAST_DELEGATE(FTankDelegate);
class UWidgetComponent;
…
private:
UWidgetComponent* Widget = nullptr;