UCLASS, UFUNCTION, UPROPERTY 사용 예시
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h" // 언리얼 엔진의 기본 타입
#include "GameFramework/Actor.h" // 액터에 대한 정보를 가지고 있는 헤더파일
#include "Item.generated.h" // 리플렉션 시스템에 관련한 헤더 파일
UCLASS() // 리플렉션 시스템에 등록해주는 키워드.
// 비워두더라도 (Blueprintable, BlueprintType)이 자동적으로 들어가있으며 블루프린트에서 상속이 가능하고 NotBlueprintable이라고 하면 블루프린트에서 상속 불가능하다는 뜻.
// BlueprintType은 블루프린트에서 이 클래스를 변수로 선언하거나 참조할 수 있게 해준다.
// (BlueprintType)만 적어놓으면 변수 선언이나 참조는 가능하지만 상속은 불가능하다는 의미
class SPARTAPROJECT_API AItem : public AActor // A 접두어는 Actor계열이라는 의미이다. Object는 U, 구조체는 F, Enum은 E
{
GENERATED_BODY() // UCLASS와 같은 역할의 매크로
public:
// Sets default values for this actor's properties
AItem();
protected:
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Item|Components") // 수정은 불가능
USceneComponent* SceneRoot;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Item|Components") // 인스턴스와 클래스 디폴트 둘 다 수정 가능
UStaticMeshComponent* StaticMeshComp;
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Item|Properties") // 클래스 디폴트만 수정 가능
float RotationSpeed;
virtual void BeginPlay() override;
virtual void Tick(float DeltaTime) override;
UFUNCTION(BlueprintCallable, Category = "Item|Actions") // 블루프린트에서 호출할 수 있는 함수
void ResetActorPosition();
UFUNCTION(BlueprintPure, Category = "Item|Properties") // 리턴 값만 받는 함수
float GetRotationSpeed() const;
UFUNCTION(BlueprintImplementableEvent, Category = "Item|Event"); // 구현은 블루프린트에서 하지만, C++에서 호출 가능하게 만드는 함수
void OnItemPickup();
};
C++ 클래스는 디폴트 값을 코드로만 수정 가능하고, 블루프린트는 에디터에서 클래스 디폴트 값을 수정할 수 있다.
C++ 클래스를 상속받은 블루프린트 - 변수
UPROPERTY 첫 번째 인자
VisibleAnywhere, EditAnywhere, EditDefaultsOnly 등이 있으며 블루프린트 상속 시 수정 가능 여부를 나타낸다.

- UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Item|Components")는 수정이 불가능한 값이므로 안 보임
- SceneRoot
- UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Item|Components") 수정이 가능하므로 보임
- StaticMeshComp
- UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Item|Properties") 클래스 디폴트에서만 수정이 가능하므로 보임
- RotationSpeed

- UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Item|Components")는 수정이 불가능한 값이므로 안 보임
- SceneRoot
- UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Item|Components") 클래스 디폴트와 인스턴스 모두 수정이 가능하므로 보임
- StaticMeshComp
- UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Item|Properties") 클래스 디폴트에서만 수정이 가능하므로 안 보임. EditInstanceOnly를 설정하면 Instance에서만 수정 가능.
- RotationSpeed
UPROPERTY 두 번째 인자
BlueprintReadOnly, BlueprintReadWrite 등이 있으며 블루프린트에서 변수로 사용할 때 Get 또는 Set이 가능한지 여부를 결정.

UPROPERTY 세 번째 인자
카테고리는 디테일 창의 카테고리를 결정. "Item|Components는" 아이템이라는 카테고리 하위에 컴포넌츠로 만든다는 뜻.
C++ 클래스를 상속받은 블루프린트 - 함수
UFUNCTION(BlueprintCallable, Category = "Item|Actions") // 블루프린트에서 호출할 수 있는 함수
void ResetActorPosition();
UFUNCTION(BlueprintPure, Category = "Item|Properties") // 리턴 값만 받는 함수
float GetRotationSpeed() const;
UFUNCTION(BlueprintImplementableEvent, Category = "Item|Event") // 구현은 블루프린트에서 하지만, C++에서 호출 가능하게 만드는 함수
void OnItemPickedUp();
void AItem::BeginPlay()
{
Super::BeginPlay();
//SetActorLocation(FVector(300.f,200.f,100.f));
//SetActorRotation(FRotator(0.f, 90.f,0.f)); // pitch, yaw, roll
//SetActorScale3D(FVector(2.0f, 2.0f, 2.0f)); // FVector(2.0f) 라고만 해도 됨
//FVector NewLocation(300.f, 200.f, 100.f);
//FRotator NewRotation(0.f, 90.f, 0.f);
//FVector NewScale(2.0f);
//FTransform NewTransform(NewRotation, NewLocation, NewScale);
//SetActorTransform(NewTransform);
OnItemPickedUp();
}
void AItem::ResetActorPosition()
{
SetActorLocation(FVector::ZeroVector); // FVector::ZeroVector는 원점을 의미
}
float AItem::GetRotationSpeed() const
{
return RotationSpeed;
}
FVector::ZeroVector는 0, 0, 0이다.
UFUNCTION의 첫 번째 인자
BlueprintCallable, BlueprintPure, BlueprintImplementableEvent 등이 있으며 C++ 클래스의 함수를 블루프린트와 호환 가능하게 해준다.






'게임 개발 > 학습 일지' 카테고리의 다른 글
| TA 코스 2주차 정리 (0) | 2026.04.13 |
|---|---|
| TA 코스 1주차 과제 - AI로 3D 모델링 생성 후 언리얼에 적용하기 (0) | 2026.04.13 |
| 언리얼 C++ - Tick 함수로 Actor의 Transform 조정하기 (0) | 2026.04.11 |
| 언리얼 C++ - Actor의 라이프 사이클 (0) | 2026.04.11 |
| 언리얼 C++ - Actor 클래스 생성 및 삭제 (0) | 2026.04.11 |