Visualizer 구성 요소
Source: Dev.to
에디터 모듈 만들기
에디터 모듈을 만들려면 런타임 모듈 이름에 Ed 또는 Editor 접미사를 붙인 새 폴더를 추가합니다(예: MyRuntime → MyRuntimeEditor).
해당 폴더에는 다음 파일들이 포함되어야 합니다:
\Private\CustomModuleEd.cpp
\Public\CustomModuleEd.h
CustomModuleEd.Build.cs
CustomModuleEd.Build.cs
using UnrealBuildTool;
public class CustomModuleEd : ModuleRules
{
public CustomModuleEd(ReadOnlyTargetRules Target) : base(Target)
{
PrivateDependencyModuleNames.AddRange(new string[]
{
"Core",
"CoreUObject",
"Engine",
"Slate",
"SlateCore",
"UnrealEd",
"ComponentVisualizers"
});
}
}
CustomModuleEd.h
#pragma once
#include "Modules/ModuleInterface.h"
#include "Modules/ModuleManager.h"
class FCustomModuleEd : public IModuleInterface
{
public:
virtual void StartupModule() override;
virtual void ShutdownModule() override;
};
CustomModuleEd.cpp
#include "CustomModuleEd.h"
#include "UnrealEdGlobals.h"
#include "Editor/UnrealEdEngine.h"
IMPLEMENT_GAME_MODULE(FCustomModuleEd, CustomModuleEd);
void FCustomModuleEd::StartupModule() {}
void FCustomModuleEd::ShutdownModule() {}
플러그인에 에디터 모듈 추가하기
플러그인의 .uplugin 파일을 편집하고 새 모듈을 추가합니다:
{
"FileVersion": 3,
...
"Modules": [
{
"Name": "CustomPlugin",
"Type": "Runtime",
"LoadingPhase": "Default"
},
{
"Name": "CustomModuleEd",
"Type": "Editor",
"LoadingPhase": "PostEngineInit"
}
]
}
Note: 로딩 단계를
PostEngineInit로 설정하십시오. 에디터에서 Tools → Debug → Modules 를 통해 모듈이 로드되었는지 확인할 수 있습니다.
디버거 컴포넌트 추가 (런타임)
에디터 비주얼라이저와 표시하려는 데이터를 연결해 줄 더미 컴포넌트를 런타임 모듈에 만들세요.
UCLASS(ClassGroup = (Custom), meta = (BlueprintSpawnableComponent))
class MYPROJECT_API UDebuggerComponent : public UActorComponent
{
GENERATED_BODY()
public:
// Sets default values for this component's properties
UDebuggerComponent();
protected:
// Called when the game starts
virtual void BeginPlay() override;
public:
// Called every frame
virtual void TickComponent(float DeltaTime, ELevelTick TickType,
FActorComponentTickFunction* ThisTickFunction) override;
/** Maximum distance at which debug geometry is drawn */
UPROPERTY(EditAnywhere, Category = "Debug")
float DrawDistance = 1000.0f;
/** Toggle drawing of debug points */
UPROPERTY(EditAnywhere, Category = "Debug")
bool ShouldDrawDebugPoints = false;
};
이 컴포넌트는 추가 속성을 노출하거나 소유 액터의 데이터를 읽을 수 있습니다. 시각화하고 싶은 모든 액터에 부착하면 됩니다.
시각화 컴포넌트 추가 (Editor)
Create a new class inside the editor module that inherits from FComponentVisualizer. This class does not need an API macro because it is not exposed to other modules.
/**
* Visualizer for UDebuggerComponent.
* No API macro – we keep it editor‑only.
*/
class TestVisualizer : public FComponentVisualizer
{
public:
/** Draws the debug visualization */
virtual void DrawVisualization(const UActorComponent* Component,
const FSceneView* View,
FPrimitiveDrawInterface* PDI) override;
protected:
/** Cached reference to the actor owning the component */
AActor* ActorRef;
private:
FVector PreviousCameraLocation;
};
구현
void TestVisualizer::DrawVisualization(const UActorComponent* Component,
const FSceneView* View,
FPrimitiveDrawInterface* PDI)
{
const UDebuggerComponent* DebuggerComp = Cast(Component);
if (!DebuggerComp || !DebuggerComp->ShouldDrawDebugPoints)
{
return;
}
// Example: draw a green point at the actor’s location
PDI->DrawPoint(ActorRef->GetActorLocation(),
FLinearColor::Green,
25.0f,
SDPG_Foreground);
}
팁: 디버깅하려는 모든 액터에
UDebuggerComponent를 부착하세요. Blueprint, 레벨에 직접 배치하거나, 액터 생성자에서CreateDefaultSubobject를 사용해 프로그래밍적으로 추가할 수 있습니다.
Registering the Visualizer (Editor Startup)
마지막으로, 에디터 모듈의 StartupModule에서 비주얼라이저를 등록하고 ShutdownModule에서 정리합니다.
void FCustomModuleEd::StartupModule()
{
if (GUnrealEd)
{
// Create and register the visualizer
TSharedPtr<TestVisualizer> TestViz = MakeShareable(new TestVisualizer());
GUnrealEd->RegisterComponentVisualizer(
UDebuggerComponent::StaticClass()->GetFName(),
TestViz);
// Notify the visualizer that it has been registered
TestViz->OnRegister();
}
}
void FCustomModuleEd::ShutdownModule()
{
if (GUnrealEd)
{
// Unregister the visualizer when the module shuts down
GUnrealEd->UnregisterComponentVisualizer(
UDebuggerComponent::StaticClass()->GetFName());
}
}
이제 에디터를 열고 UDebuggerComponent를 포함하는 액터를 선택하면, TestVisualizer가 컴포넌트 설정에 따라 디버그 포인트를 그립니다.
아래는 원래 구조와 의미를 유지하면서 정리한 동일한 내용입니다.
// Example snippet (C++)
gerComponent::StaticClass()->GetFName());
}
}
Enter fullscreen mode
Exit fullscreen mode
이제 컴파일하고 에디터를 실행하십시오. 디버거 컴포넌트가 붙어 있는 액터를 선택하면, DrawVisualization 함수 안에 정의한 대로 PDI가 디버그 시각화를 그립니다.