게임 개발자를 위한 C++ 문법 3-2

1. WHAT
UE_LOG의 다양한 예시
void TestUELogExamples()
{
// 1. 일반 로그(Log) - 개발자가 디버깅을 위해 사용하는 기본 메시지
UE_LOG(LogTemp, Log, TEXT("Game has started. Player has joined the game."));
// 2. 중요 정보(Display) - 항상 표시되는 정보 메시지
FString PlayerName = TEXT("Player1");
UE_LOG(LogTemp, Display, TEXT("Welcome, %s! Enjoy the game."), *PlayerName);
// 3. 경고(Warning) - 잠재적 문제가 있을 때 경고를 출력
int PlayerHealth = 50;
if (PlayerHealth < 100)
{
UE_LOG(LogTemp, Warning, TEXT("Player health is below maximum: %d"), PlayerHealth);
}
// 4. 오류(Error) - 실행에 영향을 줄 수 있는 문제
int AmmoCount = 0;
if (AmmoCount == 0)
{
UE_LOG(LogTemp, Error, TEXT("No ammo left! Player cannot shoot."));
}
// 5. 문자열 결합 - 다양한 데이터를 한 메시지로 출력
int Score = 150;
int TimeLeft = 120;
UE_LOG(LogTemp, Log, TEXT("Score: %d, Time Left: %d seconds."), Score, TimeLeft);
// 6. 부동소수점(Floating Point) 값 출력
float PlayerSpeed = 325.5f;
UE_LOG(LogTemp, Display, TEXT("Player speed: %.2f units/sec"), PlayerSpeed);
// 7. 여러 심각도 사용 - 게임 상태에 따라 로그를 구분
bool bIsPaused = true;
if (bIsPaused)
{
UE_LOG(LogTemp, Warning, TEXT("Game is currently paused."));
}
else
{
UE_LOG(LogTemp, Log, TEXT("Game is running normally."));
}
// 8. 디버깅용 메시지 (Developer Note)
UE_LOG(LogTemp, Display, TEXT("This message is for developers to debug the game state."));
}
2. FIX
그냥 간단하게 UE 에서 엑터 생성해서 로그에 Hello, World를 찍고 싶었을 뿐인데...
오류가 42개가 뜨는 것이다..💦
비주얼 스튜디오가 2022, 2026 둘 다 설치되어있어서 2022을 쓰지만 UE에서 2026랑 연결한 모양이다..
봉재 튜터님과 열심히 해결한 방법!

.vs 삭제 >
uproject > 추가 옵션 표시 > Generate Visual Studio project files
> 다시 vs 랑 연결 해주면 해결~ 👍👍👍👍👍 튜터님 짱
3. RESULT
- 숙제 - UE_LOG를 활용한 로또번호생성기 구현
// Called when the game starts or when spawned
void AMyActor::BeginPlay()
{
Super::BeginPlay();
//랜덤 숫자 범위 설정
int MinValue = 1;
int MaxValue = 45;
//정수형 배열 생성
TArray<int32> Numbers;
Numbers.Add(FMath::RandRange(MinValue, MaxValue));
while (Numbers.Num() < 6) {
int RandomNum = FMath::RandRange(MinValue, MaxValue); // 1 ~ 45
if (!Numbers.Contains(RandomNum)) {
Numbers.Add(RandomNum);
}
}
FString str = FString::FromInt(Numbers[0]);
for (int i = 1; i < 6; i++) {
str += ", " + FString::FromInt(Numbers[i]);
}
UE_LOG(LogTemp, Log, TEXT("Lotto Numbers: %s"), *str);
}

4. 참고
https://rhksgml78.tistory.com/665
[언리얼5] CPP 자주사용하는 FMath 함수
Unreal Engine의 C++ 프로그래밍에서 FMath 클래스는 다양한 수학적 연산과 유틸리티를 제공합니다. 이 클래스를 통해 게임 개발에 필요한 수학적 계산을 보다 쉽게 수행할 수 있습니
rhksgml78.tistory.com
분명 언리얼 C++ 처음하는거 아닌데 너무 낯설어요 하나도 기억이 안나요...ㅠ
'내배캠Unreal_TIL > UE' 카테고리의 다른 글
| [TIL] 2026-01-08 | 언리얼 엔진 기본 구조, 빌드 문제 해결, Actor 클래스에 컴포넌트 추가 (0) | 2026.01.08 |
|---|---|
| [TIL] 2025-12-24 | 과제 5 구현, 레벨 테스트 후기 (1) | 2025.12.24 |
| [UE5] 언리얼 엔진 그림자 깨질 때.. 해결, 나나이트 (0) | 2025.12.08 |
| [TIL] 2025-12-04 | 환경 디자인, 머티리얼 애니메이션 (0) | 2025.12.04 |
| [TIL] 2025-12-03 | 오버랩 이벤트, Find Look at Rotation, 플레이어 따라 움직이기, Hit (0) | 2025.12.03 |