스토리지

Unreal 로깅 2 본문

Unreal Engine/0. Unreal 5

Unreal 로깅 2

ljw4104 2023. 7. 10. 17:26

1. 값 기록하기

거의 C의 PRINTF함수와 유사함.

UE_LOG(LogTemp, Warning, TEXT("DeltaTime: %f"), DeltaTime);

하지만 FString을 가져올 때는 해당 변수의 포인터를 가져와야 출력가능하다.

FString Name = GetName();
FString Message = FString::Printf(TEXT("Item Name : %s"), *Name);

 

2. 구체 그리기

1. BluePrint에서 구체 그리기

Draw Debug Sphere 를 사용하면 됨.

해당 객체의 위치는 Get Actor Location 블럭을 사용하면 백터 형태로 반환된다.

 

2. 스크립트로 그리기

#include "DrawDebugHelpers.h"

if (UWorld* World = GetWorld())
{
    FVector Location = GetActorLocation();
    DrawDebugSphere(World, Location, 25.f, 24, FColor::Red, false, 30.f);
}

원을 그릴 때는 DrawDebugHelpers라는 헤더를 추가해줘야한다.

 

3. 선 긋기

1. BluePrint 사용

해당 객체의 X축 방향 (Forward방향)으로 Debug Line을 그림

 

2. 스크립트로 그리기

FVector Location = GetActorLocation();
FVector Forward = GetActorForwardVector();
if (UWorld* World = GetWorld())
{
    DrawDebugLine(World, Location, Location + Forward * 100.f, FColor::Red, true, -1.f, 0, 1.f);
}

 

4. 포인트 그리기

1. BluePrint로 그리기

Point는 거리에 상관없이 크기가 일정하기 때문에 멀리서 보면 커보이고 가까이서 보면 작게 보인다.

 

2. 스크립트로 그리기

if (UWorld* World = GetWorld())
{
    DrawDebugPoint(World, Location + Forward * 100.f, 15.f, FColor::Red, true);
}

 

 

5. 위의 과정들을 매크로로 따로 분류하기

매번 디버그 할 때마다 저렇게 적는건 매우 불편하다.

그래서 C++의 #define문을 사용하면 함수 매크로로 만들어서 사용할 수 있다.

#define DRAW_SPHERE(Location) if (GetWorld()) DrawDebugSphere(GetWorld(), Location, 25.f, 12, FColor::Red, true)
#define DRAW_LINE(StartLocation, EndLocation) if (GetWorld()) DrawDebugLine(GetWorld(), StartLocation, EndLocation, FColor::Red, true, -1.f, 0, 1.f)
#define DRAW_POINT(Location) if (GetWorld()) DrawDebugPoint(GetWorld(), Location, 15.f, FColor::Red, true)
#define DRAW_VECTOR(StartLocation, EndLocation) if (GetWorld()) \
	{\
		DrawDebugLine(GetWorld(), StartLocation, EndLocation, FColor::Red, true, -1.f, 0, 1.f); \
		DrawDebugPoint(GetWorld(), EndLocation, 15.f, FColor::Red, true); \
	}

// define문에서 줄바꿈을 하고 싶으면 \ 를 추가하면 된다.

DRAW_SPHERE(Location);
//DRAW_LINE(Location, Location + Forward * 100);
//DRAW_POINT(Location + Forward * 100);
DRAW_VECTOR(Location, Location + Forward * 100);

 

'Unreal Engine > 0. Unreal 5' 카테고리의 다른 글

Component  (0) 2023.07.11
UPROPERTY / UFUNCTION  (0) 2023.07.11
Unreal 로깅  (0) 2023.07.07
Unreal 기본 cpp 파일 구조  (0) 2023.07.07
언리얼 5에서 Folige에 바람에 흔들리는 효과 넣기  (0) 2023.07.06
Comments