


코드로 델리게이트 바인딩하기
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "Blueprint/UserWidget.h"
#include "LA_HUD.generated.h"
/**
*
*/
UCLASS()
class LASTARTEMIS_API ULA_HUD : public UUserWidget
{
GENERATED_BODY()
public:
// UMG 위젯이 화면에 “실제로 생성되고 붙을 때” 호출되는 C++ 초기화 함수
virtual void NativeConstruct() override;
//
UFUNCTION(BlueprintImplementableEvent)
void UpdateHP(float Current, float Max);
void BindHealth();
};
// Fill out your copyright notice in the Description page of Project Settings.
#include "UI/LA_HUD.h"
#include "Kismet/GameplayStatics.h"
#include "GameFramework/Character.h"
#include "Character/Player/Component/LA_HealthComponent.h"
#include "UI/LA_HUD.h"
void ULA_HUD::NativeConstruct()
{
Super::NativeConstruct();
BindHealth();
}
void ULA_HUD::BindHealth()
{
// OnHealthChanged에 UpdateHP 함수 바인딩
ACharacter* PlayerCharacter =
UGameplayStatics::GetPlayerCharacter(GetWorld(), 0);
ULA_HealthComponent* HealthComp = PlayerCharacter->FindComponentByClass<ULA_HealthComponent>();
if (HealthComp)
{
HealthComp->OnHealthChanged.AddDynamic(this, &ULA_HUD::UpdateHP);
// 바인딩 직후 한번 실행해줌
UpdateHP(HealthComp->GetCurrentHealth(), HealthComp->GetMaxHealth());
UE_LOG(LogTemp, Log, TEXT("HUD: Binding & Initial Update Success!"));
}
}'게임 개발 > 프로젝트' 카테고리의 다른 글
| 언리얼 내배캠 CH.3 팀 프로젝트 - 오디오/사운드 볼륨 설정 만들기 (0) | 2026.05.20 |
|---|---|
| 언리얼 내배캠 CH.3 팀 프로젝트 - 옵션 설정 체크박스 만들기 (0) | 2026.05.19 |
| 언리얼 내배캠 CH.3 팀 프로젝트 - 임무 선택 화면 만들기 (0) | 2026.05.11 |
| 언리얼 내배캠 CH.3 팀 프로젝트 - 메인 메뉴 만들기 (0) | 2026.05.04 |
| C++ 팀프로젝트 - 텍스트 RPG 게임 만들기(5) (0) | 2026.04.01 |