Debug Text & Shapes

Debug Text

Metin halinde çıktı almak için iki tane metodumuz var:

  1. UE_LOG : Verilen metni konsola bastırır.
  2. GEngine->AddOnScreenDebugMessage() : Verilen metni oyun ekranına bastırır.
void AItem::BeginPlay(){
	Super::BeginPlay();
	
	// log ekranına basar
	UE_LOG(LogTemp, Warning, TEXT("Begin play called"));
	
	// ekrana basar 
	if (GEngine) {
		GEngine->AddOnScreenDebugMessage(1, 5.0f, FColor::Red, FString("The game is over"));
	}
}

Aynı işlevi gören blueprint node’ları aşağıda verilmiştir.

  • Print String: Oyun ekranına ve log ekranına verilen çıktıyı basar
  • Log String: Log ekranına verilen çıktıyı basar

Formatlı Metinler

Tıpkı C dilindeki printf fonksiyonu gibi formatlı bir şekilde çıktı almamız da mümkündür:

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

if (GEngine) {
	FString message = FString::Printf(TEXT("Delta time: %f"), DeltaTime);
	GEngine->AddOnScreenDebugMessage(1, 5.0f, FColor::Green, message);
}

// Stringlerle çalışırken * operatörünü koymayı unutmamalıyız
if (GEngine) {
	//FString name = GetName(); // -> objenin adını döndürür
	FString name = "Mehmet"; 
	FString message = FString::Printf(TEXT("My name is %s"), *name);
	GEngine->AddOnScreenDebugMessage(2, 5.0f, FColor::Green, message);
}
// *name FString nesnesi içerisindeki TCHAR array'ını (Pointer) döndürüyor. 
// Eğer FString boşsa boş bir string döndürüyor. 
// Tıpkı C-Style string gibi 

💡 When using %s parameters to include FStrings, the * operator must be used to return the TCHAR* required for the %s parameter.

Debug Shapes

Öncelikle yardımcı header’ımızı ekleyelim:

#include "DrawDebugHelpers.h"

Debug Spheres

	UWorld* world = GetWorld();
	if (world) {
		DrawDebugSphere(world, GetActorLocation(), 150.f, 8, FColor::Red, true);
		DrawDebugSphere(world, GetActorLocation(), 170.f, 8, FColor::Green, false, 20);
	}
  • InWorld : İçinde bulunduğu dünyanın pointerı. Bu pointerı GetWorld() fonksiyonuyla elde ediyoruz. Emin olmak için bir nullcheck den geçiriyoruz.
  • Center : Kürenin merkezi. GetActorLocation() fonksiyonuyla aktörün şuanki lokasyonunu alıyoruz.
  • Radius : Kürenin yarıçapı
  • Segments : Kürenin kaç segmentten olacağını bildriiyoruz.
  • Color : Kürenin rengi
  • bPersistentLines : Çizgilerin kalıcı olup olmadığı.
  • LifeTime : Kürenin ekranda ne kadar süre kalacağı.
  • DepthPriority : Hangi çizginin önde kalacağının öncelik sıralaması
  • Thickness : Çizgilerin kalınlığı

Debug Lines

Çizgi çizmek, küre çizmekle aynı mantıkta. Farlı olarak sadece LineStart ve LineEnd parametreleriyle çizginin başını ve sonunu belirtiyoruz.

UWorld* world = GetWorld();

if (world) {
	FVector line_start = GetActorLocation();
	FVector line_end = line_start + GetActorForwardVector() * 200; 
	DrawDebugLine(world, line_start, line_end, FColor::Purple, true, -1.f, 0U, 2.f);
}

Debug Points

Nokta çizmek için konumu ve boyutunu parametre olarak vermemiz yeterli. Burada önemli bir fark diğerlerine göre noktanın ekrandaki boyutu hep sabit kalıyor. Yani yakından bakarken 10 piksellik alan kaplıyorsa uzaktan bakarken de 10 piksellik alan kaplayacaktır.

UWorld* world = GetWorld();

if (world) {
	FVector line_end = GetActorLocation() + GetActorForwardVector() * 200;
	DrawDebugPoint(world, line_end, 10.f, FColor::Yellow, true);
}

Noktayı daha önceki oluşturduğumuz çizginin uç kısmına eklemek istedim.

Diğer şekiller

Unreal bizlere debuging için çok fazla opsiyon sunuyor. Bunlara göz atmak için Visual Studio’da mouse ile herhangi bir debuging fonksiyonunun üzerine gelerek fn12 tuşuna tıklarsanız sizi o fonksiyonun tanımlandığı yere götürüyor:

FORCEINLINE void FlushPersistentDebugLines(const UWorld* InWorld) {}
FORCEINLINE void DrawDebugLine(const UWorld* InWorld, FVector const& LineStart, FVector const& LineEnd, FColor const& Color, bool bPersistentLines = false, float LifeTime = -1.f, uint8 DepthPriority = 0, float Thickness = 0.f) {}
FORCEINLINE void DrawDebugPoint(const UWorld* InWorld, FVector const& Position, float Size, FColor const& PointColor, bool bPersistentLines = false, float LifeTime = -1.f, uint8 DepthPriority = 0) {}
FORCEINLINE void DrawDebugDirectionalArrow(const UWorld* InWorld, FVector const& LineStart, FVector const& LineEnd, float ArrowSize, FColor const& Color, bool bPersistentLines = false, float LifeTime = -1.f, uint8 DepthPriority = 0, float Thickness = 0.f) {}
FORCEINLINE void DrawDebugBox(const UWorld* InWorld, FVector const& Center, FVector const& Extent, FColor const& Color, bool bPersistentLines = false, float LifeTime = -1.f, uint8 DepthPriority = 0, float Thickness = 0.f) {}
FORCEINLINE void DrawDebugBox(const UWorld* InWorld, FVector const& Center, FVector const& Extent, const FQuat& Rotation, FColor const& Color, bool bPersistentLines = false, float LifeTime = -1.f, uint8 DepthPriority = 0, float Thickness = 0.f) {}
FORCEINLINE void DrawDebugCoordinateSystem(const UWorld* InWorld, FVector const& AxisLoc, FRotator const& AxisRot, float Scale, bool bPersistentLines = false, float LifeTime = -1.f, uint8 DepthPriority = 0, float Thickness = 0.f) {}
FORCEINLINE void DrawDebugCrosshairs(const UWorld* InWorld, FVector const& AxisLoc, FRotator const& AxisRot, float Scale, const FColor& Color = FColor::White, bool bPersistentLines = false, float LifeTime = -1.f, uint8 DepthPriority = 0) {}
FORCEINLINE void DrawDebugCircle(const UWorld* InWorld, const FMatrix& TransformMatrix, float Radius, int32 Segments, const FColor& Color, bool bPersistentLines = false, float LifeTime = -1.f, uint8 DepthPriority = 0, float Thickness = 0.f, bool bDrawAxis = true) {}
FORCEINLINE void DrawDebugCircle(const UWorld* InWorld, FVector Center, float Radius, int32 Segments, const FColor& Color, bool bPersistentLines = false, float LifeTime = -1.f, uint8 DepthPriority = 0, float Thickness = 0.f, FVector YAxis = FVector(0.f, 1.f, 0.f), FVector ZAxis = FVector(0.f, 0.f, 1.f), bool bDrawAxis = true) {}
FORCEINLINE void DrawDebugCircleArc(const UWorld* InWorld, FVector const& Center, float Radius, FVector const& Direction, float AngleWidth, int32 Segments, const FColor& Color, bool bPersistentLines = false, float LifeTime = -1.f, uint8 DepthPriority = 0, float Thickness = 0.f) {}
FORCEINLINE void DrawDebug2DDonut(const UWorld* InWorld, const FMatrix& TransformMatrix, float InnerRadius, float OuterRadius, int32 Segments, const FColor& Color, bool bPersistentLines = false, float LifeTime = -1.f, uint8 DepthPriority = 0, float Thickness = 0.f) {}
FORCEINLINE void DrawDebugSphere(const UWorld* InWorld, FVector const& Center, float Radius, int32 Segments, FColor const& Color, bool bPersistentLines = false, float LifeTime = -1.f, uint8 DepthPriority = 0, float Thickness = 0.f) {}
FORCEINLINE void DrawDebugCylinder(const UWorld* InWorld, FVector const& Start, FVector const& End, float Radius, int32 Segments, FColor const& Color, bool bPersistentLines = false, float LifeTime = -1.f, uint8 DepthPriority = 0, float Thickness = 0.f) {}
FORCEINLINE void DrawDebugCone(const UWorld* InWorld, FVector const& Origin, FVector const& Direction, float Length, float AngleWidth, float AngleHeight, int32 NumSides, FColor const& Color, bool bPersistentLines = false, float LifeTime = -1.f, uint8 DepthPriority = 0, float Thickness = 0.f) {}
FORCEINLINE void DrawDebugAltCone(const UWorld* InWorld, FVector const& Origin, FRotator const& Rotation, float Length, float AngleWidth, float AngleHeight, FColor const& DrawColor, bool bPersistentLines = false, float LifeTime = -1.f, uint8 DepthPriority = 0, float Thickness = 0.f) {}
FORCEINLINE void DrawDebugString(const UWorld* InWorld, FVector const& TextLocation, const FString& Text, class AActor* TestBaseActor = NULL, FColor const& TextColor = FColor::White, float Duration = -1.000000, bool bDrawShadow = false, float FontScale = 1.f) {}
FORCEINLINE void DrawDebugFrustum(const UWorld* InWorld, const FMatrix& FrustumToWorld, FColor const& Color, bool bPersistentLines = false, float LifeTime = -1.f, uint8 DepthPriority = 0, float Thickness = 0.f) {}
FORCEINLINE void DrawCircle(const UWorld* InWorld, const FVector& Base, const FVector& X, const FVector& Y, const FColor& Color, float Radius, int32 NumSides, bool bPersistentLines = false, float LifeTime = -1.f, uint8 DepthPriority = 0, float Thickness = 0) {}
FORCEINLINE void DrawDebugCapsule(const UWorld* InWorld, FVector const& Center, float HalfHeight, float Radius, const FQuat& Rotation, FColor const& Color, bool bPersistentLines = false, float LifeTime = -1.f, uint8 DepthPriority = 0, float Thickness = 0) {}
FORCEINLINE void DrawDebugCamera(const UWorld* InWorld, FVector const& Location, FRotator const& Rotation, float FOVDeg, float Scale = 1.f, FColor const& Color = FColor::White, bool bPersistentLines = false, float LifeTime = -1.f, uint8 DepthPriority = 0) {}
FORCEINLINE void DrawCentripetalCatmullRomSpline(const UWorld* InWorld, TConstArrayView<FVector> Points, FColor const& Color, float Alpha = 0.5f, int32 NumSamplesPerSegment = 8, bool bPersistentLines = false, float LifeTime = -1.f, uint8 DepthPriority = 0, float Thickness = 0.f) {}
FORCEINLINE void DrawCentripetalCatmullRomSpline(const UWorld* InWorld, TConstArrayView<FVector> Points, TConstArrayView<FColor> Colors, float Alpha = 0.5f, int32 NumSamplesPerSegment = 8, bool bPersistentLines = false, float LifeTime = -1.f, uint8 DepthPriority = 0, float Thickness = 0.f) {}
FORCEINLINE void FlushDebugStrings(const UWorld* InWorld) {}
FORCEINLINE void DrawDebugSolidBox(const UWorld* InWorld, FBox const& Box, FColor const& Color, const FTransform& Transform = FTransform::Identity, bool bPersistent = false, float LifeTime = -1.f, uint8 DepthPriority = 0) {}
FORCEINLINE void DrawDebugSolidBox(const UWorld* InWorld, FVector const& Center, FVector const& Extent, FColor const& Color, bool bPersistent = false, float LifeTime = -1.f, uint8 DepthPriority = 0) {}
FORCEINLINE void DrawDebugSolidBox(const UWorld* InWorld, FVector const& Center, FVector const& Extent, FQuat const& Rotation, FColor const& Color, bool bPersistent = false, float LifeTime = -1.f, uint8 DepthPriority = 0) {}
FORCEINLINE void DrawDebugMesh(const UWorld* InWorld, TArray<FVector> const& Verts, TArray<int32> const& Indices, FColor const& Color, bool bPersistent = false, float LifeTime = -1.f, uint8 DepthPriority = 0) {}
FORCEINLINE void DrawDebugSolidPlane(const UWorld* InWorld, FPlane const& P, FVector const& Loc, float Size, FColor const& Color, bool bPersistent = false, float LifeTime = -1, uint8 DepthPriority = 0) {}
FORCEINLINE void DrawDebugSolidPlane(const UWorld* InWorld, FPlane const& P, FVector const& Loc, FVector2D const& Extents, FColor const& Color, bool bPersistent = false, float LifeTime = -1, uint8 DepthPriority = 0) {}
FORCEINLINE void DrawDebugFloatHistory(UWorld const & WorldRef, FDebugFloatHistory const & FloatHistory, FTransform const & DrawTransform, FVector2D const & DrawSize, FColor const & DrawColor, bool const & bPersistent = false, float const & LifeTime = -1.f, uint8 const & DepthPriority = 0) {}
FORCEINLINE void DrawDebugFloatHistory(UWorld const & WorldRef, FDebugFloatHistory const & FloatHistory, FVector const & DrawLocation, FVector2D const & DrawSize, FColor const & DrawColor, bool const & bPersistent = false, float const & LifeTime = -1.f, uint8 const & DepthPriority = 0) {}
FORCEINLINE void DrawDebugCanvas2DLine(UCanvas* Canvas, const FVector& Start, const FVector& End, const FLinearColor& LineColor) {}
FORCEINLINE void DrawDebugCanvas2DLine(UCanvas* Canvas, const FVector2D& StartPosition, const FVector2D& EndPosition, const FLinearColor& LineColor, const float& LineThickness = 1.f) {}
FORCEINLINE void DrawDebugCanvas2DCircle(UCanvas* Canvas, const FVector2D& Center, float Radius, int32 NumSides, const FLinearColor& LineColor, const float& LineThickness = 1.f) {}
FORCEINLINE void DrawDebugCanvas2DBox(UCanvas* Canvas, const FBox2D& Box, const FLinearColor& LineColor, const float& LineThickness = 1.f) {}
FORCEINLINE void DrawDebugCanvasLine(UCanvas* Canvas, const FVector& Start, const FVector& End, const FLinearColor& LineColor) {}
FORCEINLINE void DrawDebugCanvasCircle(UCanvas* Canvas, const FVector& Base, const FVector& X, const FVector& Y, FColor Color, float Radius, int32 NumSides) {}
FORCEINLINE void DrawDebugCanvasHalfCircle(UCanvas* Canvas, const FVector& Base, const FVector& X, const FVector& Y, FColor Color, float Radius, int32 NumSides) {}
FORCEINLINE void DrawDebugCanvasWireSphere(UCanvas* Canvas, const FVector& Base, FColor Color, float Radius, int32 NumSides) {}
FORCEINLINE void DrawDebugCanvasWireCone(UCanvas* Canvas, const FTransform& Transform, float ConeRadius, float ConeAngle, int32 ConeSides, FColor Color) {}
FORCEINLINE void DrawDebugCanvasWireBox(UCanvas* Canvas, const FMatrix& Transform, const FBox& Box, FColor Color) {}
FORCEINLINE void DrawDebugCanvasCapsule(UCanvas* Canvas, const FMatrix& Transform, float HalfLength, float Radius, const FColor& LineColor) {}

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *